Pulling a .csv out of a database

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
mccommunity
Forum Commoner
Posts: 62
Joined: Mon Oct 07, 2002 8:55 am

Pulling a .csv out of a database

Post by mccommunity »

I need to create a .csv on the fly from a simple select * from table. Instead of listing it on the page I need it to write either a .csv or an .xls comma delimited file. Anyone know the best way to do this or can point me in the right direction? Thanks.


Mark
kcomer
Forum Contributor
Posts: 108
Joined: Tue Aug 27, 2002 8:50 am

Post by kcomer »

My usual steps for this.

1. Run the query
2. Create the column headings using the rows returned form the query(must be using associative array results).
3. Loop through the results and add them to a variable(comma seperated if you like) with a new line at the end of each row.
4. clean the output buffers, send the correct headers to force a download and echo out the variable you saved the data to

Keith
Post Reply