0
我正在使用此代碼,如上所述here。從php導出數據到CSV csv
$file = date('dmY-His');
header("Content-type: text/csv");
header("Content-Disposition: attachment; filename=visitors-$file.csv");
header("Pragma: no-cache");
header("Expires: 0");
$sql = "select id, ip, server, time, date from visitors";
$res = mysql_query($sql);
$data = array();
$data[] = array('id', 'ip', 'server', 'time', 'date');
while ($row = mysql_fetch_array($res)) {
$data[] = array_values($row);
}
$output = fopen("php://output", "w");
foreach ($data as $val) {
fputcsv($output, $val);
}
fclose($output);
首先,這個程序不工作對我localhost
但工程罰款server
。爲什麼?
其次,我得到的數據中包含兩個條目,即
+----+----+---------+---------+-----------+
| id | ip | server | time | date |
+----+----+---------+---------+-----------+
| 1 | 1 | :::1 | :::1 | server1 | server1 | 10:00:00 am | 12-12-2012 |
+----+----+---------+---------+-----------+----------+-------------+------------+
| 2 | 2 | :::2 | :::2 | server2 | server2 | 10:15:00 am | 13-12-2012 |
+----+----+---------+---------+-----------+----------+-------------+------------+
啓用錯誤報告,看看是否輸出任何錯誤消息。如果你想得到準確的答案,「單獨工作」不會有用。 –
它對你的本地主機有什麼作用? – srain
它只是給了我一個PHP文件 –