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.
Dynamic Export to CSV
Moderator: General Moderators
-
ale8oneboy
- Forum Newbie
- Posts: 5
- Joined: Wed May 19, 2010 9:53 am
Re: Dynamic Export to CSV
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
?>
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
?>
- AbraCadaver
- DevNet Master
- Posts: 2572
- Joined: Mon Feb 24, 2003 10:12 am
- Location: The Republic of Texas
- Contact:
Re: Dynamic Export to CSV
Nice list of phone numbersmarnieg 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.
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
Re: Dynamic Export to CSV
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.
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.
-
ale8oneboy
- Forum Newbie
- Posts: 5
- Joined: Wed May 19, 2010 9:53 am
Re: Dynamic Export to CSV
My bad.
header("Content-Disposition: attachment; filename='export.csv'");
header("Content-Disposition: attachment; filename='export.csv'");
Re: Dynamic Export to CSV
I' calling all the chicks nowAbraCadaver wrote:Nice list of phone numbersmarnieg 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.
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
Re: Dynamic Export to CSV
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.