<?php
session_start();
include("dbf.php");
$contents = "<html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" /></head><body>";
$tbla=$_SESSION[tbl];
$fieldsu=$_SESSION[fieldsu];
$que=$_SESSION[qury];
$contents .="<table border='1'><tr  style='color: white'>";
$contents .="<td bgcolor='gray'>رديف</td>";
foreach($fieldsu as $name => $value)
  $contents .= "<td bgcolor='gray'>$name</span></td>";
$contents .="</tr>";
$q=mysql_query($que);
$i=1;
while($r=mysql_fetch_array($q))
{
  $contents .="<tr>";
  $contents .="<td>$i</td>";
 foreach($fieldsu as $name => $value)
  $contents .= "<td >$r[$value]</span></td>";
$contents .="</tr>";
$i++;
}
$contents .="</table>";
$contents .= "</body></html>";
header("Content-type: application/octet-stream");
header("Content-Disposition: attachment; filename=$tbla.xls");
header("Pragma: no-cache");
header("Expires: 0");
echo $contents;

?>