CSV 仅导出标题数组而不是数据
CSV export only heading Arrays not Data
我正在尝试使用以下代码导出和下载包含 mysql 条记录的 csv 文件;
header('Content-Type: text/csv; charset=utf-8');
header('Content-Disposition: attachment; filename=DepReport_'.$from.'_'.$to.'.csv');
$output = fopen('php://output', 'w');
fputcsv($output, array('Reference',
'Depart Date / Time',
'Depart Terminal',
'Depart Flight'
)
);
$i = 2;
while($rows = mysql_fetch_array($result)) {
fputcsv($data[$i], array($rows['ReferenceNo'],
date('Y-m-d',strtotime($rows['DepartDate'])).' '.$rows['DepartTime'],
$rows['DepartTerminal'],
$rows['DepartFlight']
)
);
$i++;
}
fputcsv($output, $data);
exit;
但只得到标题数组而没有记录
需要帮助来修复代码。
此致
将您的结果放入 $output 流
while($rows = mysql_fetch_array($result)) {
fputcsv($output, array($rows['ReferenceNo'],
date('Y-m-d',strtotime($rows['DepartDate'])).' '.$rows['DepartTime'],
$rows['DepartTerminal'],
$rows['DepartFlight']
)
);
}
在循环中以同样的方式写出来怎么样?
header('Content-Type: text/csv; charset=utf-8');
header('Content-Disposition: attachment; filename=DepReport_'.$from.'_'.$to.'.csv');
$output = fopen('php://output', 'w');
fputcsv($output, array('Reference',
'Depart Date / Time',
'Depart Terminal',
'Depart Flight'
)
);
$i = 2;
while($rows = mysql_fetch_array($result)) {
//change to $output so it writes lines to same handler
fputcsv($output, array($rows['ReferenceNo'],
date('Y-m-d',strtotime($rows['DepartDate'])).' '.$rows['DepartTime'],
$rows['DepartTerminal'],
$rows['DepartFlight']
)
);
$i++;
}
//fputcsv($output, $data);
//don't need anymore
exit;
我正在尝试使用以下代码导出和下载包含 mysql 条记录的 csv 文件;
header('Content-Type: text/csv; charset=utf-8');
header('Content-Disposition: attachment; filename=DepReport_'.$from.'_'.$to.'.csv');
$output = fopen('php://output', 'w');
fputcsv($output, array('Reference',
'Depart Date / Time',
'Depart Terminal',
'Depart Flight'
)
);
$i = 2;
while($rows = mysql_fetch_array($result)) {
fputcsv($data[$i], array($rows['ReferenceNo'],
date('Y-m-d',strtotime($rows['DepartDate'])).' '.$rows['DepartTime'],
$rows['DepartTerminal'],
$rows['DepartFlight']
)
);
$i++;
}
fputcsv($output, $data);
exit;
但只得到标题数组而没有记录
需要帮助来修复代码。
此致
将您的结果放入 $output 流
while($rows = mysql_fetch_array($result)) {
fputcsv($output, array($rows['ReferenceNo'],
date('Y-m-d',strtotime($rows['DepartDate'])).' '.$rows['DepartTime'],
$rows['DepartTerminal'],
$rows['DepartFlight']
)
);
}
在循环中以同样的方式写出来怎么样?
header('Content-Type: text/csv; charset=utf-8');
header('Content-Disposition: attachment; filename=DepReport_'.$from.'_'.$to.'.csv');
$output = fopen('php://output', 'w');
fputcsv($output, array('Reference',
'Depart Date / Time',
'Depart Terminal',
'Depart Flight'
)
);
$i = 2;
while($rows = mysql_fetch_array($result)) {
//change to $output so it writes lines to same handler
fputcsv($output, array($rows['ReferenceNo'],
date('Y-m-d',strtotime($rows['DepartDate'])).' '.$rows['DepartTime'],
$rows['DepartTerminal'],
$rows['DepartFlight']
)
);
$i++;
}
//fputcsv($output, $data);
//don't need anymore
exit;