HELP! I'm trying to dump a table out of MySQL to a CSV file and then automatically start a download for the end-user. I can't seem to get it right. Can anyone assist?
Here is the code:
<?PHP
header( "Content-type: application/x-something" );
header( "Content-Disposition: attachment; filename=table.csv" );
header( "Content-Description: PHP4 Generated Data" );
?>
<?PHP
mysql_connect(localhost, name, pswd);
mysql_select_db("je_berean");
$query = "SELECT * FROM bereanclass";
$result = mysql_query($query);
while ($row = (mysql_fetch_row($result))) {
for ($i = 0 ; $i < count($row); $i++) {
if (!is_string($row[$i])) {
print $row[$i].",";
}
else {
print "\"".$row[$i]."\",";
}
}
print "\n";
}
?>
<?PHP
exit( );
?>