pozer69 Posted February 4, 2009 Share Posted February 4, 2009 <?php $host = 'localhost'; $user = 'gotbizbr_researc'; $pass = '******'; $db = 'gotbizbr_research'; $table = 'companies'; $file = 'companies'; $link = mysql_connect($host, $user, $pass) or die("Can not connect." . mysql_error()); mysql_select_db($db) or die("Can not connect."); $result = mysql_query("SHOW COLUMNS FROM " . $table . ""); $i = 0; if(mysql_num_rows($result)>0) { while ($row = mysql_fetch_assoc($result)) { $csv_output .= $row['Field']."; "; $i++; } } $csv_output .= "\n"; $values = mysql_query("SELECT * FROM ".$table.""); 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; ?> Link to comment https://forums.phpfreaks.com/topic/143728-need-help-w-php-code-export-mysql-to-excel/ Share on other sites More sharing options...
Mark Baker Posted February 4, 2009 Share Posted February 4, 2009 Are you sure that if(mysql_num_rows($result)>0) { is exactly as typed here, and that you don't have a spurious ? somewhere before the > Link to comment https://forums.phpfreaks.com/topic/143728-need-help-w-php-code-export-mysql-to-excel/#findComment-754184 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.