Using php I am converting a mysql table into a csv file. Then offering the user the option of opening or saving the file. All is good except that all of the data appears in the first cell of the Excel spreadsheet when the file is opened. The values are all enclosed in "" 'sand separated by ,'s. The code is shown here.
Thank you in advance for any help you can give me.
Cheers
<?php
$table = "data_export";
$result=mysql_query("select * from $table");
$out = '';
// Get all fields names in table
$fields = mysql_list_fields("my_db",$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 .="\r\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 .="\r\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');
?>
Thanks again