Hi all,
I am using the following code to export a table of data from SQL to CSV format.
This works great however the final column 'selections' may sometimes be in the format of 21, 34, 56 or in a single number.Code:header("Content-type: application/octet-stream"); header("Content-Disposition: attachment; filename=UserData.csv"); header("Pragma: no-cache"); header("Expires: 0"); mysql_select_db($database_conf, $conf); $select = "SELECT username, email, , organisation, selections FROM users"; $export = mysql_query($select); $count = mysql_num_fields($export); for ($i = 0; $i < $count; $i++) { $header .= mysql_field_name($export, $i).","; } while($row = mysql_fetch_row($export)) { $line = ''; foreach($row as $value) { if ((!isset($value)) OR ($value == "")) { $value = "\t"; } else { $value = str_replace('"', '""', $value); $value = '"' . $value . '"' . ","; } $line .= $value; } $data .= trim($line)."\n"; } $data = str_replace("\r", "", $data); if ($data == "") { $data = "\n(0) Records Found!\n"; } print "$header\n$data"; exit;
Is it possible to output the values stored with commas into separate columns. e.g...
|Selections| | |
--------------------------
| 21 | 11 | 40 |
Thanks!




Reply With Quote