I am stuck on this one problem… For example, i am using exit();
it works, but it works only with first selected row, not with all. If i am using echo to display data, it displays perfecly. If i am trying to make it to work without exit(); its does not work at all. Any suggestions to how to fix this?
$vet = $_GET['vet'];
$name = $_GET['name'];
// etc...
$data = fopen('php://output', 'w');
fputcsv($data,array('ID', 'Name', 'Email address', etc...));
// selection query (it works perfecly)
foreach...
// echo query for tests (it works perfectly)
fputcsv($data, array($id, $name, $email, etc...));
header('Content-Type: text/csv; charset=utf-8');
header('Content-Disposition: attachment; filename='. $name .'.csv');
exit();
endforeach....
The
header
s &exit
should be after theloop
ends. Currently it is adding the first row and then exiting the loop. As a result only one row is present. The loop should run all the iterations to add all the rows to the file.