Page 1 of 1
Dynamic Export to CSV
Posted: Wed May 19, 2010 1:43 pm
by marnieg
I have a page in my website that dynamically echos data from several tables and uses literals. I would like the user to have the option of export this data to a CSV so they can open it in their version of Excel. All of the examples I have seen for fputcsv or other functions only export data from a specific table or array. Is there a way to export this data to a csv file?
Here is what the page looks like with the data echoed.
Link removed
Or maybe there is another function I'm not aware of to open a file and write out line by line the data displayed.
Re: Dynamic Export to CSV
Posted: Wed May 19, 2010 2:50 pm
by ale8oneboy
Not exactly sure what you're looking for. But If you're looking to export the data as CSV. You could try changing the header to CSV and then echo everything out line by line.
Example:
<?php
header("Content-type: application/octet-stream");
header("Content-Disposition: attachment; filename="myfile.csv");
//line1
echo "column1,column2,column3\r\n";
//line2
echo "column1,column2,column3\r\n";
//loops or whatever here to echo out line by line
?>
Re: Dynamic Export to CSV
Posted: Wed May 19, 2010 3:08 pm
by AbraCadaver
marnieg wrote:I have a page in my website that dynamically echos data from several tables and uses literals. I would like the user to have the option of export this data to a CSV so they can open it in their version of Excel. All of the examples I have seen for fputcsv or other functions only export data from a specific table or array. Is there a way to export this data to a csv file?
Here is what the page looks like with the data echoed.
Link removed
Or maybe there is another function I'm not aware of to open a file and write out line by line the data displayed.
Nice list of phone numbers

Re: Dynamic Export to CSV
Posted: Wed May 19, 2010 3:22 pm
by marnieg
get an error on the line header("Content-Disposition: attachment; filename="export.csv");
Parse error: syntax error, unexpected T_STRING
Should there be another " here to close this statement. My biggest problem is with PHP syntax, when to use " or ' quotes.
Re: Dynamic Export to CSV
Posted: Wed May 19, 2010 3:37 pm
by ale8oneboy
My bad.
header("Content-Disposition: attachment; filename='export.csv'");
Re: Dynamic Export to CSV
Posted: Wed May 19, 2010 3:40 pm
by mikosiko
AbraCadaver wrote:marnieg wrote:I have a page in my website that dynamically echos data from several tables and uses literals. I would like the user to have the option of export this data to a CSV so they can open it in their version of Excel. All of the examples I have seen for fputcsv or other functions only export data from a specific table or array. Is there a way to export this data to a csv file?
Here is what the page looks like with the data echoed.
Link removed
Or maybe there is another function I'm not aware of to open a file and write out line by line the data displayed.
Nice list of phone numbers

I' calling all the chicks now

Re: Dynamic Export to CSV
Posted: Wed May 19, 2010 3:44 pm
by John Cartwright
Since your using real people's personal information (and they probably didn't consent to this being public), plus it's not important to see the table.. I've removed the link.