Page 1 of 1
Pulling a .csv out of a database
Posted: Wed Jul 23, 2003 1:45 pm
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
Posted: Wed Jul 23, 2003 1:50 pm
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