While downloading the csv file it displaying the values in column wise. here is the code:
$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);}}
And also need to add add the header in row wise.
Please find the screenshot how the csv file need to be