Forum Moderators: coopster
header("Content-type: application/vnd.ms-excel");
header("Content-Disposition: attachment; filename=testInvitationReport.xls");
header("Content-Transfer-Encoding: BINARY");
//include("dbconnect.inc.php");
mysql_connect("$host","$user", "$pass");
@mysql_select_db("$db") or die("Unable to select database");
$select = "SELECT * FROM testTable";
$export = mysql_query($select);
$count = mysql_num_fields($export);
for ($i = 0; $i < $count; $i++)
{
$header .= mysql_field_name($export, $i)."\t";
}
while($row = mysql_fetch_row($export))
{
$line = '';
foreach($row as $value)
{
if ((!isset($value)) OR ($value == ""))
{
$value = "\t";
}
else
{
$value = str_replace('"', '""', $value);
$value = '"' . $value . '"' . "\t";
}
$line .= $value;
}
$data .= trim($line)."\n";
}
$data = str_replace("\r", "", $data);
if ($data == "")
{
$data = "\n(0) Records Found!\n";
}
print "$header\n$data";
$line = str_replace("\r", "", $line);
$line = str_replace("\n", "", $line);
I also took out this line:
$data = str_replace("\r", "", $data);
becuase it wasn't doing anything after the two lines above.
header("Content-type: application/vnd.ms-excel");
header("Content-Disposition: attachment; filename=testInvitationReport.xls");
header("Content-Transfer-Encoding: BINARY");
it works fine , i am using like that 4 my reports
I'm not sure what you are suggesting here. Do you mean for kuper20 to add those headers to the top of the script? If so, if you check the original post you'll see that that is already the case. :)