Jump to content

Downlaodabe Export .csv


GD77

Recommended Posts

$file = 'export';
$tbl="tbl_xxx";
$qry_expEm = mysql_query("SHOW COLUMNS FROM `".$tbl."`");
$i = 0;
if (mysql_num_rows($qry_expEm) > 0) {
while ($row = mysql_fetch_assoc($qry_expEm)) {
$csv_output .= $row['Field']."; ";
$i++;
}
}
$csv_output .= "\n";
$values = mysql_query("SELECT * FROM `".$tbl."`");
while ($rowr = mysql_fetch_row($values)) {
for ($j=0;$j<$i;$j++) {
$csv_output .= $rowr[$j]."; ";
}
$csv_output .= "\n";
}
$filename = $file."_".date("Y-m-d_H-i",time());
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;

 

using this common script why does it output all HTML codes of the current page?

Link to comment
https://forums.phpfreaks.com/topic/270169-downlaodabe-export-csv/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.