Pachman3000 Posted August 11, 2011 Share Posted August 11, 2011 Hi guys, can someone please take a look at this and help me adjust the script so it will create new columns for each heading and value. For example, I would like the csv to look like this: Name Email Bob [email protected] Currently, all the values are just listed in one column. $db_handle = mysql_connect($server, $user_name, $password); $db_found = mysql_select_db($database, $db_handle); $result = mysql_query("SHOW COLUMNS FROM ".$table.""); $i = 0; if (mysql_num_rows($result) > 0) { while ($row = mysql_fetch_assoc($result)) { $csv_output .= $row['Field']."\t "; $i++; } } $csv_output .= "\n"; $values = mysql_query("SELECT * FROM ".$table.""); while ($rowr = mysql_fetch_row($values)) { for ($j=0;$j<$i;$j++) { $csv_output .= $rowr[$j]."\r\n "; } $csv_output .= "\n"; } $filename = $file."_".date("Y-m-d_H-i",time()); header("Content-type: application/vnd.ms-excel"); header("Content-disposition: csv" . date("Y-m-d") . ".csv"); header( "Content-disposition: filename=".$filename.".csv"); print $csv_output; exit; Thank you for the help. Link to comment https://forums.phpfreaks.com/topic/244548-creating-new-columns-while-exporting-to-csv/ Share on other sites More sharing options...
fenway Posted August 11, 2011 Share Posted August 11, 2011 CSV has no "formatting" other than the comma. Link to comment https://forums.phpfreaks.com/topic/244548-creating-new-columns-while-exporting-to-csv/#findComment-1256136 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.