Hi,
I am having a problem with extracting database in .xls format from php. I give the codes below. Everything is fine with the codes except that I see a repetition of rows in the extracted .xls format. Could someone help me out?
<?php
//microsoft sql server connection here
//write data to xls file
$fp=fopen("./data.xls","wb");
$query = "SELECT DISTINCT uId,uName, address, contactNo FROM User";
$result=mssql_query($query);
$columns="<table>";
$columns.=
"<tr><td>"."User Id".</td><td>"."User Name."</td><td>".
"Address"."</td><td>"."Contact No"."</td><tr>";
fwrite($fp,$columns);
$columns="</table>";
$data="<table>";
if ($result)
{
while ($r = mssql_fetch_array($result))
{
$uId=$r["uId"];
$uName=$r["uName"];
$address=$r["address"];
$contactNo=$r["contactNo"];
$data.="<tr><td>".$uId."</td><td>".$uName."</td><td>".
$address."</td><td>".$contactNo."</td></tr>";
fwrite($fp,$data);
}
$data="</table>";
echo "<p align=center><font size=5>"."An XLS file has been created.";
}
else {
echo "No data. There maybe an error in the database.";
}
fclose($fp);
mssql_free_result($result);
?>
Many thanks in adavance...
I am having a problem with extracting database in .xls format from php. I give the codes below. Everything is fine with the codes except that I see a repetition of rows in the extracted .xls format. Could someone help me out?
<?php
//microsoft sql server connection here
//write data to xls file
$fp=fopen("./data.xls","wb");
$query = "SELECT DISTINCT uId,uName, address, contactNo FROM User";
$result=mssql_query($query);
$columns="<table>";
$columns.=
"<tr><td>"."User Id".</td><td>"."User Name."</td><td>".
"Address"."</td><td>"."Contact No"."</td><tr>";
fwrite($fp,$columns);
$columns="</table>";
$data="<table>";
if ($result)
{
while ($r = mssql_fetch_array($result))
{
$uId=$r["uId"];
$uName=$r["uName"];
$address=$r["address"];
$contactNo=$r["contactNo"];
$data.="<tr><td>".$uId."</td><td>".$uName."</td><td>".
$address."</td><td>".$contactNo."</td></tr>";
fwrite($fp,$data);
}
$data="</table>";
echo "<p align=center><font size=5>"."An XLS file has been created.";
}
else {
echo "No data. There maybe an error in the database.";
}
fclose($fp);
mssql_free_result($result);
?>
Many thanks in adavance...