GD77 Posted November 1, 2012 Share Posted November 1, 2012 (edited) $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? Edited November 1, 2012 by GD77 Quote 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 (edited) 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. Edited November 2, 2012 by smoseley Quote 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. Quote Link to comment https://forums.phpfreaks.com/topic/270169-downlaodabe-export-csv/#findComment-1389535 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.