The below php code can help you :
Code:
<?php
// DB Connection here
$select = "SELECT * FROM table_name";
$export = mysql_query($select) or die("Sql error : " . mysql_error());
$fields = mysql_num_fields($export);
for($i = 0; $i < $fields; $i++)
{
$header .= mysql_field_name($export , $i). "\t";
}
while($row = mysql_fetch_row($export))
{
$line = '';
foreach($row as $value)
{
if(!isset($value) || trim($value) == "")
{
$value = "\t";
}
else
{
$value = str_replace('"' , '""' , $value);
$value = '"' . $value . '"' . "\t";
}
$line .= $value;
}
$data .= trim($line). "\n";
}
$data = str_replace("\r" , "" , $data);
if(trim($data) == "")
{
$data = "\n(0)Records Found!\n";
}
header("Content-type: application/msexcel");
header("Content-Disposition: attachment; filename=your_desired_name.xls");
header("Pragma: no-cache");
header("Expires: 0");
print "$header\n$data";
?>
See this thread : export data in the bd Mysql to the Excel file
Bookmarks