GD77 Posted November 1, 2012 Share Posted November 1, 2012 $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 More sharing options...
smoseley Posted November 2, 2012 Share Posted November 2, 2012 That script should not be placed inside a page. It should be its own PHP script (e.g. csv.php), which you would link to from another page. Link to comment https://forums.phpfreaks.com/topic/270169-downlaodabe-export-csv/#findComment-1389473 Share on other sites More sharing options...
GD77 Posted November 2, 2012 Author Share Posted November 2, 2012 Thank you very much. Link to comment https://forums.phpfreaks.com/topic/270169-downlaodabe-export-csv/#findComment-1389535 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.