My problem was to output the MYSQL results into a text file, available for downloading as a *.csv file. I solved it this way:
//make a temp-filename
$tmp = tempnam ("/var/www/html/Secure/Reports/tmp", "Whitepaper_CSV." );
//open the file
$fp = @fopen($tmp, "w");
if (!$fp) { die("Cannot open $tmp"); }
//loop through MYSQL result
While ($query_data = mysql_fetch_array($results))
{
//print the data to the file
fputs ($fp, $query_data["field1"] );
//print a comma
fputs ($fp, ", ");
fputs ($fp, $query_data["field2"] );
fputs ($fp, ", ");
fputs ($fp, $query_data["field3"] );
//newline
fputs ($fp, "\n");
}
//close the file
@fclose($fp);
Yes, you could further improve this, but it
reads easy, and works.
the data was then imported to Excel...