Hi,
Why the my first record is lost when the script has exported the data to excel.
Can anyone help me?,
function ExportToExcel()
{
include("connect.php";
mysql_select_db("dbit_aksbtm";
$buffer = "";
$separator = ",";
$newline = "\r\n";
$sql = "SELECT e.EmployeeID AS EMPLOYEE_ID,
e.EmpFirstName AS FIRST_NAME,
e.EmpLastName AS LAST_NAME,
e.EmpLogon AS LOGON_NAME,
e.EmpLogonSAPID AS LOGON_SAP_ID,
e.emp_EmailAddress AS EMAIL_ADDRESS,
sp.PCsSpecName AS PC_SPEC,
p.PCsID AS PC_ID
FROM tblemployees e,
tblsections s,
tblpcs p,
tblpcsspec sp
WHERE s.sectionID = e.sectionID
AND p.PCsID = e.PCsID
AND sp.PCsSpecID = e.PCsSpecID
AND e.Status = 0
ORDER BY EmpFirstName ASC";
$result = mysql_query($sql);
$row = mysql_fetch_assoc($result);
while(list($key, $value) = each($row))
{
$key = str_replace('_', ' ', $key);
$buffer .= "\"".$key."\"".$separator;
//$buffer .= "\"".$value."\"".$separator;
}
$buffer .= $newline;
while ($row = mysql_fetch_assoc($result))
{
while(list($key, $value) = each($row))
{
$buffer .= "\"".$value."\"".$separator;
}
$buffer .= $newline;
}
header("Content-type: application/vnd.ms-excel";
header("Content-Length: ".strlen($buffer));
header("Content-Disposition: attachment; filename=report.csv";
header("Expires: 0";
header("Cache-Control: must-revalidate, post-check=0,pre-check=0";
header("Pragma: public";
echo $buffer;
}
Thanks & regards,
Discussion14php