Comments on: PHP: Export Query Results to a CSV File http://www.terminally-incoherent.com/blog/2007/07/05/php-export-query-results-to-a-csv-file/ I will not fix your computer. Tue, 04 Aug 2020 22:34:33 +0000 hourly 1 https://wordpress.org/?v=4.7.26 By: Joe Broderick http://www.terminally-incoherent.com/blog/2007/07/05/php-export-query-results-to-a-csv-file/#comment-20560 Fri, 21 Oct 2011 04:17:50 +0000 http://www.terminally-incoherent.com/blog/2007/07/05/php-export-query-results-to-a-csv-file/#comment-20560

That warning means that you used a PHP header() declaration to try and set some page headers AFTER you output some HTML to the server. PHP is reminding you that all page headers and such must be done before any HTML is sent to the client because once the HTML is sent to the client, it’s no longer on the server and no server-side scripting can be done at that point.

Reply  |  Quote
]]>
By: Prashanth http://www.terminally-incoherent.com/blog/2007/07/05/php-export-query-results-to-a-csv-file/#comment-20531 Tue, 18 Oct 2011 12:09:25 +0000 http://www.terminally-incoherent.com/blog/2007/07/05/php-export-query-results-to-a-csv-file/#comment-20531

Dear Luke,

Thanks for your code.
Here is a small error on server.But works well in local host.

Warning: Cannot modify header information – headers already sent by (output started at /home/xxx/public_html/xxx.php:1) in /home/xxx/public_html/xxx.php on line 24

Please solve this issue. I tried many ways but in vain. please help

Reply  |  Quote
]]>
By: Hans http://www.terminally-incoherent.com/blog/2007/07/05/php-export-query-results-to-a-csv-file/#comment-19658 Sat, 09 Jul 2011 22:21:11 +0000 http://www.terminally-incoherent.com/blog/2007/07/05/php-export-query-results-to-a-csv-file/#comment-19658

Thanks for tips

Reply  |  Quote
]]>
By: Glenn Geiger http://www.terminally-incoherent.com/blog/2007/07/05/php-export-query-results-to-a-csv-file/#comment-18779 Mon, 28 Mar 2011 21:55:33 +0000 http://www.terminally-incoherent.com/blog/2007/07/05/php-export-query-results-to-a-csv-file/#comment-18779

Sorry, the code tags are not working here. If anyone wants to see what I meant, you can contact me through my website.

Reply  |  Quote
]]>
By: Glenn Geiger http://www.terminally-incoherent.com/blog/2007/07/05/php-export-query-results-to-a-csv-file/#comment-18778 Mon, 28 Mar 2011 21:54:27 +0000 http://www.terminally-incoherent.com/blog/2007/07/05/php-export-query-results-to-a-csv-file/#comment-18778

Works like a charm! Thank you for sharing this valuable snippet.

As a side, I wanted to allow the user to submit a query, for example a date range, and view the results on the screen. Then as an option, click a link to export that data.

I’m doing it by attaching the query to the URL and retrieving it with GET. Here’s my link:
<a href="export.php?query=">Export this
I’ve got your function in a functions.php file. The export.php file looks like this:

No Query in the URL

It’s working, but if anyone has a suggestion how I can improve on this, please let me know.

Reply  |  Quote
]]>
By: Avay http://www.terminally-incoherent.com/blog/2007/07/05/php-export-query-results-to-a-csv-file/#comment-16687 Fri, 30 Jul 2010 06:35:44 +0000 http://www.terminally-incoherent.com/blog/2007/07/05/php-export-query-results-to-a-csv-file/#comment-16687

This code export all the data whenwe click in the page. But I want to have a link or click button on the right most part of each record. After clicking it I want to execute the function(expor to csv file). Can any one give idea how to use it in this case?

Reply  |  Quote
]]>
By: Luke Maciak http://www.terminally-incoherent.com/blog/2007/07/05/php-export-query-results-to-a-csv-file/#comment-13276 Wed, 30 Sep 2009 15:14:56 +0000 http://www.terminally-incoherent.com/blog/2007/07/05/php-export-query-results-to-a-csv-file/#comment-13276

@ Mandy:

Ok, try this. In status.php just make a regular HTML link to csv_export.php. Then in csv_export.php do this:

< ?php 

// copy and paste my function here

// fill this out with your db username, password, etc
$link = mysql_connect('mysql_host', 'mysql_user', 'mysql_password');
mysql_select_db('my_database');
 
// run an appropriate query
$result = mysql_query("SELECT * FROM my_table");
 
// pass the result to my function:
csv_from_mysql_resource($result);

?>

Make sure you don’t have any blank spaces or empty lines above or below the <?php and ?> – that will cause the script to throw errors about headers being already set.

I hope this helps.

Reply  |  Quote
]]>
By: Mandy http://www.terminally-incoherent.com/blog/2007/07/05/php-export-query-results-to-a-csv-file/#comment-13275 Wed, 30 Sep 2009 08:28:52 +0000 http://www.terminally-incoherent.com/blog/2007/07/05/php-export-query-results-to-a-csv-file/#comment-13275

@ Luke Maciak:
I am totally confused. I’ve been trying to find a script that works for me. I’ve tried several only to come to a dead end on all of them. Maybe I’m still a newbie :( I want my users to simply click a text link to download the CSV file. But I can’t work it out :(
– the text link is in my file “status.php”
– I have your function script in a file called “csv_export.php”
Do I add the above script into status.php or another page?
How do I call the function when the link is clicked??

Sorry for what may seem an obvious answer :(

Reply  |  Quote
]]>
By: Michael http://www.terminally-incoherent.com/blog/2007/07/05/php-export-query-results-to-a-csv-file/#comment-11748 Mon, 09 Mar 2009 11:45:58 +0000 http://www.terminally-incoherent.com/blog/2007/07/05/php-export-query-results-to-a-csv-file/#comment-11748

Brilliant ! Thank you for posting this. You saved a good portion of what is left of my sanity :)

I’ve wanted to figure this out for ages.

Reply  |  Quote
]]>
By: Dave http://www.terminally-incoherent.com/blog/2007/07/05/php-export-query-results-to-a-csv-file/#comment-9750 Thu, 31 Jul 2008 15:48:01 +0000 http://www.terminally-incoherent.com/blog/2007/07/05/php-export-query-results-to-a-csv-file/#comment-9750

Thanks. I tried several scripts to do this but yours was simplest and most effective.

Reply  |  Quote
]]>