下载csv文件时,它以列方式显示值。 这是代码:
$id=1;
getPackage($certificate_id);
header('Content-Type: application/excel');
header('Content-Disposition: attachment; filename="sample.csv"');
function getPackage($id){
$q_pack="select p.filename,p.version from cert c join packages p on c.package_id=p.id left join documents dt on p.id=dt.package_id left join documents doc on doc.id=d.document_id where c.certificate_id=$id";
$res_pack = db_query($q_pack);
if ($res_pack) {
while ($pack_row = db_fetch_object($res_pack)){
$fp = fopen('php://output', 'w');
foreach ( $pack_row as $line ) {
$val = explode(",", $line);
fputcsv($fp, $val);}
fclose($fp);}}
答案 0 :(得分:1)
你有很多方法,一种简单的方法可以从查询中注入值,例如:
$q_pack="select 'filename', 'version' from dual union select p.filename,p.version from cert c join packages p on c.package_id=p.id left join documents dt on p.id=dt.package_id left join documents doc on doc.id=d.document_id where c.certificate_id=$id";
否则基于提取的第一次交互的其他一些技巧