Posts Tagged ‘simple csv export’

Easiest Way to make Downloadable CSV Files

Monday, February 27th, 2012

Here is the quick example for creating a CSV file.

First Give a Header Definition:
$filename = “Vehicle_Export”.”_”.date(“Y-m-d_H-i”,time());

//Generate the CSV file header
header(“Content-type: application/vnd.ms-excel”);
header(“Content-disposition: csv” . date(“Y-m-d”) . “.csv”);
header(“Content-disposition: filename=”.$filename.”.csv”);

Then create your query and loop the headings and values…
$createHeader = 0;

while( $row = mysql_fetch_array($q) ){
for( $i=0; $i