Dear All,
I am trying to download the data from mysql to excel (CSV). I get a quote but when i download the data, its fetching the only data but I want to put the column name also.
Please help me in putting the column name. in the excel file.
Thanks in advance
Regards,
Robin.
I am trying to download the data from mysql to excel (CSV). I get a quote but when i download the data, its fetching the only data but I want to put the column name also.
Code:
<?php
include_once("db_connect.inc.php");
$query = "SELECT * FROM logintable";
$result = mysql_query($query) or die('Error, query failed');
$tsv = array();
$html = array();
while($row = mysql_fetch_array($result, MYSQL_NUM))
{
$tsv[] = implode("\t", $row);
$html[] = "<tr><td>" .implode("</td><td>", $row) . "</td></tr>";
}
$tsv = implode("\r\n", $tsv);
$html = "<table>" . implode("\r\n", $html) . "</table>";
$fileName = 'logintable.xls';
header("Content-type: application/vnd.ms-excel");
header("Content-Disposition: attachment; filename=$fileName");
echo $tsv;
//echo $html;
?>
Thanks in advance
Regards,
Robin.
Comment