while ($line = mysql_fetch_array($result))
{
if ($first)
{ foreach ($line as $key => $value)
{ if ($first)
{ fwrite($file_handle, $key); $first = FALSE; }
else
{ fwrite($file_handle, ", $key"); }
}
fwrite ($file_handle, "\n");
}
$number1 = TRUE;
foreach ($line as $value)
{
if ($number1) { fwrite ($file_hande, $value); $number1 = FALSE; } else { fwiret ($file_hande, ", {$value}"; };
}
fwrite ($file_handle, "\n");
}
Here is a little more efficient code:
if ($row = mysql_fetch_assoc($result)) {
$line = '';
foreach ($row as $key => $value) {
$line .= "$key,";
}
fwrite($file_handle, substr($line, 0, -1)."\n");do {
$line = '';
foreach ($row as $value) {
if (strpos($value, '"') ) {
$line .= sprintf('"%s",', str_replace('"', '\\"', $value));
} else {
$line .= "$value,";
}
}
fwrite($file_handle, substr($line, 0, -1)."\n");} while ($line = mysql_fetch_assoc($result)); }
-- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php

