Is it possible to copy a mysql database to an excel worksheet writting PHP code..

please help with code.

Recommended Answers

All 4 Replies

yes I have read your article and its helpful.. thans a lot

ok, Glad I was able to help. You can post your queries in the "Ask an Expert" section also.

check this code mysql to excel

<?php
ob_start("ob_gzhandler");
include("../config/dbconfig.php");
$result = mysql_query('select * from ra_salesreport');
$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/octet-stream");
header("Content-Disposition: attachment; filename=resume.xls");
header("Pragma: no-cache");
header("Expires: 0");
echo $header."\n".$data;
?>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.