Is it possible to take the results of a query and write them out to either a comma delimited file or to an excel file?
Printable View
Is it possible to take the results of a query and write them out to either a comma delimited file or to an excel file?
Got it except for writing to an actual excel file:PHP Code:$filename = 'test.csv';
$somecontent = "Add this to the file\n";
// Let's make sure the file exists and is writable first.
//if (is_writable($filename)) {
// In our example we're opening $filename in append mode.
// The file pointer is at the bottom of the file hence
// that's where $somecontent will go when we fwrite() it.
if (!$handle = fopen($filename, 'a')) {
echo "Cannot open file ($filename)";
exit;
}
// Write $somecontent to our opened file.
if (fwrite($handle, $somecontent) === FALSE) {
echo "Cannot write to file ($filename)";
exit;
}
echo "Success, wrote ($somecontent) to file ($filename)";
fclose($handle);
/*} else {
echo "The file $filename is not writable";
}
And I have no idea why it's doubling up my code. :ehh:
If you still want to dump the results into an Excel file then look at COM()
http://uk.php.net/manual/en/ref.com.php
There is also some comments about using excel with mysql I think.
Hope it helps