i try to learn how to export data to csv using this script, yes i can export all data but in csv i found one error(when run in localhost) :
<b>Notice</b>: Undefined variable: csv_output in <b>C:\xampp\htdocs\import_export\index.php</b> on line <b>10</b><br />
not sure why, but i can run this code in live server without any issue.
Full code
error_reporting(E_ALL);
mysql_connect("localhost", "root", "") or die(mysql_error());
mysql_select_db("csv") or die(mysql_error());
$file = "product_export"; // csv name.
//CSV Header
$csv_output .= "ID " . ", ";
$csv_output .= "Content " . ", ";
$csv_output .= "
";
//CSV Content rows
$query = mysql_query("SELECT * FROM `users`");
while ($row = mysql_fetch_array($query)) {
$csv_output .= $row["id"] . ", ";
$csv_output .= $row["content"] . ", ";
$csv_output .= "
";
}
$filename = $file . "_" . date("d-m-Y_H-i");
header("Content-type: application/vnd.ms-excel");
header("Content-disposition: csv" . date("Y-m-d") . ".csv");
header("Content-disposition: filename=" . $filename . ".csv");
print $csv_output;
exit;
p/s : im using mysql_* for testing only.