我有以下几点:
$name = 'registrations.csv';
header('Content-Type: text/csv');
header('Content-Disposition: attachment; filename='. $name);
header('Pragma: no-cache');
header("Expires: 0");
$outstream = fopen("php://output", "w");
$results = mysql_query("select * from registrations");
while( $result = mysql_fetch_array($results) )
{
fputcsv($outstream, $result);
}
fclose($outstream);这很有效,除了它给出了每列中的两个。例如,我在表中有一个given_name列和一个surname列。生成的csv文件将每列显示两次。为什么?
发布于 2013-03-06 01:39:41
将mysql_fetch_array()更改为mysql_fetch_assoc()。mysql_fetch_array()同时获取数据库结果的数值数组和关联数组。
while( $result = mysql_fetch_assoc$results) )
{
fputcsv($outstream, $result);
}https://stackoverflow.com/questions/15230470
复制相似问题