我正在使用array创建 CSV 文件。但是创建的文件未正确创建。
PHP代码
$sss=mysql_query("SELECT DATE(pdate),COUNT(*) AS mycount FROM qchat_sessions WHERE MONTH(pdate)='09' GROUP BY DATE(pdate)");
$array=array();
while($rows = mysql_fetch_array($sss)){
$array[] = array ($rows[0], $rows[1]);
}
header("Content-type: application/csv");
header("Content-Disposition: attachment; filename=test.csv");
$fp = fopen('php://output', 'w');
foreach ($array as $row) {
fputcsv($fp, $row);
}
fclose($fp);
它使用页面的数据和HTML创建文件CSV。但我只想要这个
2013-09-26 1 2013-09-27 2 2013-09-28 2
CSV文件中的。为何使用HTML生成CSV?
由于
答案 0 :(得分:0)
$sss=mysql_query("SELECT DATE(pdate),COUNT(*) AS mycount FROM qchat_sessions WHERE MONTH(pdate)='09' GROUP BY DATE(pdate)");
$array=array();
$array[] = array('Column1', 'Column2');
while($rows = mysql_fetch_array($sss)){
$array[] = array ($rows[0], $rows[1]);
}
header("Content-type: application/csv");
header("Content-Disposition: attachment; filename=test.csv");
$fp = fopen('php://output', 'w');
foreach ($array as $row) {
fputcsv($fp, $row);
}
fclose($fp);
exit;