Possible Duplicate:
PHP code to convert a MySQL query to CSV
i'm trying to export a csv file and i'd need to create space between the fields of the database printed because everything comes as a simple row.
What i need to do is also print in the header the name of the field.. here is the code i have. First i need to export fields in a csv tab or just space between fields...
if ( !$result1 ) { echo mysql_error(); }
while ($row = mysql_fetch_array($result1)) {
$last = end($row);
foreach ($row as $item) {
fwrite($fh, $item);
if ($item != $last)
fwrite($fh, "\t");
}
fwrite($fh, "\n");
}
fclose($fh);