grimmier Posted March 19, 2007 Share Posted March 19, 2007 I have a working excel sheet export. But it does not export the first row of data. Here is my code. <?php require_once('Connections/inventory.php'); ?> <?php $specs = explode("&", $_SERVER['QUERY_STRING']); session_start(); $currentPage = $_SERVER["PHP_SELF"]; $query_Recordset1 = 'SELECT * FROM Inventory WHERE `Invoice Number` = "0" AND `Model` = "'.$specs[0].'" AND `Equipment Type` = "monitor"'; mysql_select_db($database_inventory, $inventory); $Recordset1 = mysql_query($query_Recordset1, $inventory) or die(mysql_error()); $row_Recordset1 = mysql_fetch_assoc($Recordset1); $totalRows_Recordset1 = mysql_num_rows($Recordset1); $fields = mysql_num_fields($Recordset1); //--------------------------------------------- //define header info for browser header("Content-Type: application/vnd.ms-excel"); header("Content-Disposition: attachment; filename=Report.xls"); header("Pragma: no-cache"); header("Expires: 0"); // show column names as names of MySQL fields for ($i = 0; $i < mysql_num_fields($Recordset1); $i++) echo mysql_field_name($Recordset1,$i) . "\t"; print("\n"); while($row = mysql_fetch_row($Recordset1)) { //set_time_limit(60); // you can enable this if you have lot of data $schema_insert = ""; for($j=0; $j < mysql_num_fields($Recordset1);$j++) { if(!isset($row[$j])) $schema_insert .= "NULL\t"; elseif ($row[$j]) $schema_insert .= "$row[$j]\t"; else $schema_insert .= "\t"; } $schema_insert = str_replace($sep."$", "", $schema_insert); $schema_insert = preg_replace("/\r\n|\n\r|\n|\r/", " ", $schema_insert); $schema_insert .= "\t"; print(trim($schema_insert)); print "\n"; } ?> Link to comment https://forums.phpfreaks.com/topic/43402-solved-argh-still-missing-data-row-1-on-excel-export/ Share on other sites More sharing options...
bwochinski Posted March 19, 2007 Share Posted March 19, 2007 You're advancing the pointer on your mySQL results before you begin the while loop with this line:: $row_Recordset1 = mysql_fetch_assoc($Recordset1); Just before your headers. Link to comment https://forums.phpfreaks.com/topic/43402-solved-argh-still-missing-data-row-1-on-excel-export/#findComment-210792 Share on other sites More sharing options...
grimmier Posted March 20, 2007 Author Share Posted March 20, 2007 Ahh thanks, I can't believe i missed that. Link to comment https://forums.phpfreaks.com/topic/43402-solved-argh-still-missing-data-row-1-on-excel-export/#findComment-211110 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.