<?php
$host = "localhost";
$username = "root";
$password = "";
mysql_connect ( $host, $username, $password );//连接mysql数据库
mysql_select_db ( "mydatabase" );//数据库名
$file = fopen ( "test.csv", "r" );//读取csv文件
$array1 = array (
"T",
"G",
"A",
"E"
);
// ID 区域 2.25-3.03 3.4-3.10 3.11-3.17
$dates = array (
array (
"startDate" => "2013-3-3",
"endDate" => "2013-2-25"
),
array (
"startDate" => "2013-3-10",
"endDate" => "2013-3-4"
),
array (
"startDate" => "2013-3-17",
"endDate" => "2013-3-11"
)
);
while ( $content = fgetcsv ( $file ) ) {//取得csv文件的一行
if (! empty ( $content ) && ! empty ( $content [0] ) ) {//如果第一个单元格的内容不为空
$id = trim ( $content [0] );
foreach ( $array1 as $arrayone ) {//一个$array1元素
$content = $id . "," .$arrayone. "," ;
foreach ( $dates as $date ) {//一个时间段
$selectSql = "select count(l.id) from table1 l,table2 s
where s.user_id = l.user
and l.createdOn < '".$date[startDate]."'
and l.endTime > '".$date[endDate]."'
and s.type='".$arrayone."'
and l.id like'" . $id . "%';";
$result = mysql_query ( $selectSql );
$rowNum = mysql_num_rows ( $result );
if ($rowNum >= 1) {
while ( $row = mysql_fetch_array ( $result, MYSQL_NUM ) ) {
$content .= $row [0] . ",";
}
} else {
// 没有记录,则为0
$content .= "0" . ",";
}
}
$content .= "*\t\n";
file_put_contents("countSkus.csv", $content, FILE_APPEND);
}
}
}
?>
$host = "localhost";
$username = "root";
$password = "";
mysql_connect ( $host, $username, $password );//连接mysql数据库
mysql_select_db ( "mydatabase" );//数据库名
$file = fopen ( "test.csv", "r" );//读取csv文件
$array1 = array (
"T",
"G",
"A",
"E"
);
// ID 区域 2.25-3.03 3.4-3.10 3.11-3.17
$dates = array (
array (
"startDate" => "2013-3-3",
"endDate" => "2013-2-25"
),
array (
"startDate" => "2013-3-10",
"endDate" => "2013-3-4"
),
array (
"startDate" => "2013-3-17",
"endDate" => "2013-3-11"
)
);
while ( $content = fgetcsv ( $file ) ) {//取得csv文件的一行
if (! empty ( $content ) && ! empty ( $content [0] ) ) {//如果第一个单元格的内容不为空
$id = trim ( $content [0] );
foreach ( $array1 as $arrayone ) {//一个$array1元素
$content = $id . "," .$arrayone. "," ;
foreach ( $dates as $date ) {//一个时间段
$selectSql = "select count(l.id) from table1 l,table2 s
where s.user_id = l.user
and l.createdOn < '".$date[startDate]."'
and l.endTime > '".$date[endDate]."'
and s.type='".$arrayone."'
and l.id like'" . $id . "%';";
$result = mysql_query ( $selectSql );
$rowNum = mysql_num_rows ( $result );
if ($rowNum >= 1) {
while ( $row = mysql_fetch_array ( $result, MYSQL_NUM ) ) {
$content .= $row [0] . ",";
}
} else {
// 没有记录,则为0
$content .= "0" . ",";
}
}
$content .= "*\t\n";
file_put_contents("countSkus.csv", $content, FILE_APPEND);
}
}
}
?>