Forum Moderators: coopster
<?php
include 'dbinfo.inc.php';
$link= mysql_connect('localhost',$username,$password);
if (!$link) {
die('Could not connect: ' . mysql_error());
}
@mysql_select_db($grant_database) or die( "Unable to select database");
$Result = $pDate = null;
$Query = "SELECT * from main LIMIT 0,20";
$Result = mysql_query($Query);
// For Headings in Excel
$contents="Project Number\tProject Name\tGrant Year\tProject Description\n";
// Put data records from mysql by while loop.
if($Result)
{
while($Row=mysql_fetch_array($Result)){
$contents.=$Row['project_number']."\t";
$contents.=$Row['project_name']."\t";
$contents.=$Row['grant_year']."\t";
$contents.=$Row['project_description']."\n";
}
}
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Content-Type: application/force-download");
header("Content-Type: application/octet-stream"); //I tried vnd.ms-excel and it still didn't work
header("Content-Type: application/download");;
header("Content-Disposition: attachment;filename=orderlist.xls ");
header("Content-Transfer-Encoding: binary ");
print_r($contents);
exit;
?>
header("Content-Type: application/excel");