0

enter image description here

I want to be able to export these results using the 'Export to CSV' button after the search has been populated. How do I go about this using PHP? I know how to get the CSV for be downloadable. My problem is how to implement the Export-to-CSV after search has been conducted.

MY MAJOR CONCERN IS HOW TO IMPLEMENT THE DOWNLOAD USING THE EXPORT TO CSV BUTTON AFTER USING THE SEARCH BUTTON TO GENERATE THE REPORTS. I already seen the many codes on CSV generation and they are not my question.

OmniPotens
  • 1,125
  • 13
  • 30
  • 1
    Write to `$_SESSION` or set `$_GET` (`method="GET"`) parameters for reusage. – BlitZ Apr 26 '13 at 09:45
  • I don't seem to understand what you mean. Please clarify a little further. – OmniPotens Apr 26 '13 at 09:46
  • 1
    Check this out http://stackoverflow.com/questions/4249432/export-to-csv-via-php – Mingebag Apr 26 '13 at 09:49
  • I've seen that but it doesn't solve my problem. Both scenarios are not the same. – OmniPotens Apr 26 '13 at 09:51
  • @OmniPotens yep but you got some got solutions so it should be possible ... if not post your code and we will help you – Mingebag Apr 26 '13 at 10:16
  • My question is, How do I implement the Export to CSV button to download the CSV file containing output from the search query? I already have the codes working fine but how do I implement the "Export to CSV" button into my code – OmniPotens Apr 26 '13 at 10:26
  • @CORRUPT Thanks for your earlier statement on the $_GET method. It gave me head to solve the puzzle and I got my code working fine now. Thumbs up! – OmniPotens Apr 26 '13 at 16:42

1 Answers1

0
header("Content-Type: application/vnd.ms-excel");
header("Pragma: no-cache");
header("Expires: 0");
header("Content-disposition: attachment; filename=export.xls");

echo 'ID' . "\t" . 'FirstName' . "\t" . 'LastName' . "\t";
echo "\n";

foreach($data as $v){
  echo $v->id . "\t" . $v->FirstName . "\t" . $v->LastName . "\t";
}

exit;