I can output a PHP table in an excel file using this code:
<?php
require("aacfs.php");
header("Content-type: application/octet-stream");
header("Content-Disposition: attachment; filename=Cancelled Flight Summary_sortbydate.xls");
header("Pragma: no-cache");
header("Expires: 0");
echo "<center>Ayala Aviation Corporation</center>";
echo "<center><b>Cancelled Flight Summary</b></center>";
echo "<center>For the period ________</center></br></br>";
$result=mysql_query("select * from reservation where status='Cancelled' order by bdate");
echo "<center></br></br><table border=1 class='imagetable'><tr>
<th>Flight Date</th>
<th>Client</th>
<th>Group Code</th>
<th>Itinerary</th>
<th>ETD</th>
<th>Aircraft</th>
<th>ETA</th>
<th>Reservation No.</th>
<th>Last Status</th>
<th>Remarks</th>
<th>Reserved By</th>
</tr>";
if(mysql_num_rows($result)>0)
{
while($row=mysql_fetch_array($result))
{
$rvno=$row['reservno'];
$yr=(string) date("Y");
$rn=$yr."-".$rvno;
echo"<tr><td>".$row['fdate']."</td><td>".$row['cliename']."</td><td>".$row['grpcode']."</td><td>".$row['itinerary']."</td><td>".$row['etd']."</td><td>".$row['acode']."</td><td>".$row['eta']."</td><td>".$rn."</td><td>".$row['lstatus']."</td><td>".$row['remarks']."</td><td>".$row['adminid']."</td></tr>";
}
}
else
{ ?>
<tr><td colspan="11" style="text-align:center; color:#FF0000; font-size:16px;">*No Data Available!*</td></tr>
<?php
}
?><?php
?>
I tried this,
<?php
require("aacfs.php");
header("Content-type: application/pdf");
header("Content-Disposition: attachment; filename=Cancelled Flight Summary_sortbydate.pdf");
header("Pragma: no-cache");
header("Expires: 0");
echo "<center>Ayala Aviation Corporation</center>";
echo "<center><b>Cancelled Flight Summary</b></center>";
echo "<center>For the period ________</center></br></br>";
$result=mysql_query("select * from reservation where status='Cancelled' order by bdate");
echo "<center></br></br><table border=1 class='imagetable'><tr>
<th>Flight Date</th>
<th>Client</th>
<th>Group Code</th>
<th>Itinerary</th>
<th>ETD</th>
<th>Aircraft</th>
<th>ETA</th>
<th>Reservation No.</th>
<th>Last Status</th>
<th>Remarks</th>
<th>Reserved By</th>
</tr>";
if(mysql_num_rows($result)>0)
{
while($row=mysql_fetch_array($result))
{
$rvno=$row['reservno'];
$yr=(string) date("Y");
$rn=$yr."-".$rvno;
echo"<tr><td>".$row['fdate']."</td><td>".$row['cliename']."</td><td>".$row['grpcode']."</td><td>".$row['itinerary']."</td><td>".$row['etd']."</td><td>".$row['acode']."</td><td>".$row['eta']."</td><td>".$rn."</td><td>".$row['lstatus']."</td><td>".$row['remarks']."</td><td>".$row['adminid']."</td></tr>";
}
}
else
{ ?>
<tr><td colspan="11" style="text-align:center; color:#FF0000; font-size:16px;">*No Data Available!*</td></tr>
<?php
}
?><?php
?>
And it does download a PDF file but it can't be opened.
Is it really impossible to output the PHP table in a PDF file the same way it does in the above code? Or I'm just doing something wrong on my 2nd code? This way is the easiest for me so I'm eager to know if it is impossible (if it is, then why?) or possible. And please point me out to an easy alternative to achieve this in case it is not possible, since I'm new to generating external files through PHP. Any help would do. Thanks.