Downloading data in excel file from database

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • robin1983
    New Member
    • Oct 2007
    • 99

    Downloading data in excel file from database

    Hi, i have a code to download the data from database to excel file. The problem is that, everything is working fine. But, actually with my code, the field name is not coming. I want to download the filed name too at the top of each column. So, i m giving my code below and tell me where should i change and what code should written do access the field name too.
    [PHP]
    <?php
    include("config .php");
    include("connec t.php");

    $sql = "SELECT * FROM employee";
    $result = mysql_query($sq l) or die(mysql_erorr ());

    $tsv = array();
    $html = array();
    while($row = mysql_fetch_arr ay($result, MYSQL_NUM))
    {
    $tsv[] = implode("\t", $row);
    $html[] = "<tr><td>".impl ode("</td><td>", $row)."</td></tr>";
    }
    $tsv = implode("\r\n", $tsv);
    $html = "<table>".implo de("\r\n", $html)."</table>";

    $fileName = 'mysql_to_excel .xls';
    header("Content-type:applicatio n/vnd.ms-excel");
    header("Content-Disposition:att achment; filename = $fileName");

    echo $tsv;
    mysql_close();
    ?>
    [/PHP]
Working...