export to csv
| From: | Home) | Date: | Wed, 06 Jun 2007 05:00:06 +0000 |
| Subject: | export to csv | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-256153@lists.php.net to get a copy of this message | ||
Hi everyone, I have a small problem when exporting mysql into csv format.
The export works fine. The problem is, if the mysql table has a carriage
return, opening the csv file in excel will display a square box where the
carriage return is.
Displaying the table on a web page is fine.
Thanks for any help.
Haig
<?php
$csv_output = 'column1';
$csv_output .= "\015\012";
$result = mysql_query("select * from table");
while($row = mysql_fetch_array($result))
{
$csv_output .= '"'.$row[column1].'"';
$csv_output .= "\015\012";
}
header("Content-type: application/vnd.ms-excel");
header("Content-disposition: attachment; filename=" .
date("Y-m-d")."_my_report".".csv");
print $csv_output;
exit;
mysql_close();
}