Hi All,
I need a script to download the mysql table to an excel file. I used the phpfreaks tutorial script but it is not opening in excel sheet.
Please help
Thanks,
anna
exporting mysql table to excel
Moderator: General Moderators
The first thing you need to do is read viewtopic.php?t=8815..
- aceconcepts
- DevNet Resident
- Posts: 1424
- Joined: Mon Feb 06, 2006 11:26 am
- Location: London
Anna,
Follow this link: http://www.phpfreaks.com/tutorials/114/0.php
Try using search engines to find scripts i.e. in this instance search for something as simple as "php to excel".
Hope the link helps
Follow this link: http://www.phpfreaks.com/tutorials/114/0.php
Try using search engines to find scripts i.e. in this instance search for something as simple as "php to excel".
Hope the link helps
use navicat
you can also use navicat, point and click no code needed
Hi All,
Thanks for your reply.
I cannot use pear class as it is not installed in my clients server.
Below is my code, this is downloading an excel file but when opened it is showing as a text file with values seperated with tab.
If anyone knows what went wrong in the code, Please let me know.
anna
Thanks for your reply.
I cannot use pear class as it is not installed in my clients server.
Below is my code, this is downloading an excel file but when opened it is showing as a text file with values seperated with tab.
Code: Select all
<?php
include('../../connection.php');
$result = mysql_query('select * from subscriber');
$count = mysql_num_fields($result);
for ($i = 0; $i < $count; $i++){
$header .= mysql_field_name($result, $i)."\t";
}
while($row = mysql_fetch_row($result)){
$line = '';
foreach($row as $value){
if(!isset($value) || $value == ""){
$value = "\t";
}else{
$value = str_replace('"', '""', $value);
$value = '"' . $value . '"' . "\t";
}
$line .= $value;
}
$data .= trim($line)."\n";
}
$data = str_replace("\r", "", $data);
if ($data == "") {
$data = "\nno matching records found\n";
}
header("Content-type: application/x-excel");
//header("Content-type: application/x-msdownload");
header ("Cache-Control: no-cache, must-revalidate");
header("Content-Disposition: attachment; filename=excelfile.xls");
header("Pragma: no-cache");
header("Expires: 0");
echo "$header\n$data";
?>anna