Jump to content

Skipping first row in excel when php file exported


dc_jt

Recommended Posts

Hi

Im exporting fields from a database into an excel file, and everything is coming out fine, except the first row in excel is being skipped and the headers (name, email, address etc) are on the 2nd row down. Why does it not start on the first row?

Here is my code:

[code]<?php
require_once($_SERVER['DOCUMENT_ROOT'].'/config.inc.php');
require_once(LOCAL_CLASSES.'/Tables/RCLTblReaders.class.php');

$oTblReaders = new RCLTblReaders();
$rReaders = $oTblReaders->GetDataP();

//Set username and password for login
$myusername = "****@********.com";
$mypassword = "****";
$areaname = "User Memories";

//If username is blank or password is blank or username or password dont match $myusername or $mypassword (above)
//show username and password login box
if ($_SERVER["PHP_AUTH_USER"] == "" || $_SERVER["PHP_AUTH_PW"] == "" || $_SERVER["PHP_AUTH_USER"] != $myusername || $_SERVER["PHP_AUTH_PW"] != $mypassword) {
  header("HTTP/1.0 401 Unauthorized");
    header("WWW-Authenticate: Basic realm=\"$areaname\"");
    echo "<h1>Authorization Required.</h1>";
  die();
}

$sCurrentDate = date("d/m/Y");

header("Content-type: application/octet-stream");
    header("Content-Disposition: attachment; filename=UserMemories".str_replace(' ','', $sUserMemories)."_".$sCurrentDate.".csv");
    header("Pragma: no-cache");
    header("Expires: 0");
   
print "Name, Email, Address, Town, City, Postcode, Country";

    while ($oReaders = mysql_fetch_object($rReaders))
{?>
<?php
print "$oReaders->name, $oReaders->email, $oReaders->address, $oReaders->town, $oReaders->city, $oReaders->postcode, $oReaders->country";

}?>[/code]

(edit to change [nobbc][quote][/quote][/nobbc] tags to [nobbc][code][/code][/nobbc] tags)

Archived

This topic is now archived and is closed to further replies.

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