but this is not working if there are commas in the database, is it?
i'm not further experienced in working with *.csv files, but if the syntax used by microsoft excel isn't wrong this should work:
PHP Code:
$file = fopen('foo.csv', 'w') or die('Unable to open file');
$rows = mysql_query('SELECT * FROM foo');
while ($r = mysql_fetch_array($rows))
{
for($x = 0; $x < count($r); $x++)
{
if (eregi(",", $r[$x]))
{
$r[$x] = '"'.$r[$x].'"';
}
}
fwrite($file, implode(',', $r) . "\n");
}
mysql_free_result($rows);
fclose($file);