【发布时间】:2015-03-09 00:24:15
【问题描述】:
我在 PHP 中有这段代码:
// output headers so that the file is downloaded rather than displayed
header('Content-Type: text/csv; charset=utf-8');
header('Content-Disposition: attachment; filename=calls.csv');
// create a file pointer connected to the output stream
$output = fopen($_SERVER["DOCUMENT_ROOT"].'/file_dump/price_tariffs/calls.csv', 'w');
// output the column headings
fputcsv($output, array('Column 1', 'Column 2'));
// loop over the rows, outputting them
$sql="SELECT * from call_costs where sequence < '50' ";
$rs=mysql_query($sql,$conn);
while($result = mysql_fetch_array($rs)) {
fputcsv($output, $result["number"]);
}
它在 price_tariffs 目录中创建文件名 calls.csv,但它只添加第 1 列和第 2 列,而不是来自 while 循环的数据
我已经检查了循环并在循环内回显数据,显示正常
【问题讨论】:
-
print_r之一的$result["number"]输出是什么? -
另外,您是要将其保存到文件中,还是让浏览器下载内容?