I'm Trying to export & download csv file containning mysql records using following code;
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;
but only getting Heading Arrays but no records
Need help to fix the code.
Regards
what about writing out the same way while in the loop?