bradkenyon Posted March 6, 2007 Share Posted March 6, 2007 i export everythinig nicely, instead of the header column being titled as whatever the table cell is titled in the db, how would i be able to add my own header titles within the csv file <? $table="forms_dieattachedsolder"; include ('db.php'); $result=mysql_query("select * from $table"); $out = ''; // Get all fields names in table "name_list" in database "qweb7". $fields = mysql_list_fields(qweb7,$table); // Count the table fields and put the value into $columns. $columns = mysql_num_fields($fields); // Put the name of all fields to $out. for ($i = 0; $i < $columns; $i++) { $l=mysql_field_name($fields, $i); $out .= '"'.$l.'",'; } $out .="\n"; // Add all values in the table to $out. while ($l = mysql_fetch_array($result)) { for ($i = 0; $i < $columns; $i++) { $out .='"'.$l["$i"].'",'; } $out .="\n"; } // Open file export.csv. $f = fopen ('export.csv','w'); // Put all values from $out to export.csv. fputs($f, $out); fclose($f); header('Content-type: application/csv'); header('Content-Disposition: attachment; filename="export.csv"'); readfile('export.csv'); ?> Link to comment https://forums.phpfreaks.com/topic/41448-export-to-csv-need-to-name-headers-for-each-column/ Share on other sites More sharing options...
monk.e.boy Posted March 6, 2007 Share Posted March 6, 2007 <?php /* // Put the name of all fields to $out. for ($i = 0; $i < $columns; $i++) { $l=mysql_field_name($fields, $i); $out .= '"'.$l.'",'; } $out .="\n"; */ $out .= '"My header 1","My header 2","etc..."'; ?> Try something like that. monk.e.boy Link to comment https://forums.phpfreaks.com/topic/41448-export-to-csv-need-to-name-headers-for-each-column/#findComment-200799 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.