View Single Post
Old 06-23-2008, 06:08 AM   #1 (permalink)
sharma.9.pooja
The Visitor
 
sharma.9.pooja's Avatar
 
Join Date: Jun 2008
Posts: 4
Thanks: 1
sharma.9.pooja is on a distinguished road
Default want to fetch data in excel sheet from my mysql database

hi all,

i want to fetch my data from database in excel sheet.please anybody help me regarding this problem..
this is my code........

<?php
$local = "localhost";
$user = "root";
$pass = "root";
$db = "contact1";


$conn = mysql_connect($local,$user,$pass) or die ("Unable to connect to database.");

mysql_select_db($db, $conn);
$sql = mysql_query("SELECT * FROM submit");
$result = mysql_query($sql) or die('Error, query failed');
$tsv = array();
$html = array();
while($row = mysql_fetch_array($result))
{
$tsv[] = implode("\t", $row);
$html[] = "<tr><td>" .implode("</td><td>", $row) .<br>
"</td></tr>";
}

$tsv = implode("\r\n", $tsv);
echo $html = "<table>" . implode("\r\n", $html) . "</table>";

$fileName = 'mysql-to-excel.xls';
header("Content-type: application/vnd.ms-excel");
header("Content-Disposition: attachment; filename=$fileName");

//echo $tsv;
echo $html;
mysql_close($conn);

?>

sharma.9.pooja is offline  
Reply With Quote