Greetings fellow coders!
I appear to be at a loss in my attempts to export the results from a SQL query to a csv file. Please take a moment to check out what I've done so far, then see what I would like it to do. Any and all help is appreciated.
Code snippet:
$sql_result = mysql_query($sql,$connection)
or die("Couldn't execute query.");
if (!$sql_result) {
echo "<P>Couldn't get item!";
} else {
$row = mysql_fetch_array($sql_result);
$yadda1 = $row["yadda1"];
$yadda2 = $row["yadda2"];
$yadda3 = $row["yadda3"];
$yadda4 = $row["yadda4"];
$csv = fopen("/path/to/report.csv", "w+");
fwrite($csv,"$yadda1,$yadda2,$yadda3,$yadda4");
fclose($csv);
echo "File Written to CSV";
This all looks fine and what not, but i have multiple results that I need written to the csv file, and not just the first result. I'm having trouble trying to figure out a way to loop the results then have them written to the file as they are returned.
Thanks!