Jump to content

[SOLVED] Argh still missing data row 1 on excel export


grimmier

Recommended Posts

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.