I'm having a problem writing the results of a MySQL query to a file using php. There are definitely results from the search, and the file is created, but when you open the file it's empty.
I think it's something to do with how I'm writing to the file, but I'm not sure.
$result = mysql_query($compsel);
if (!result) die("unable to process query: " . mysql_error());
$fp = fopen('results.csv', 'w');
mysql_data_seek($result, 0); //set data pointer to 0
$rw = mysql_fetch_array($result, MYSQL_ASSOC);
print_r($rw);
foreach ($rw as $fields) {
fputcsv($fp, $fields);
}
fclose($fp);
Thanks in advance!