0

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

please help with code.

3
Contributors
4
Replies
5
Views
10 Years
Discussion Span
Last Post by rahulb310
0

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

0

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;
?>

Edited by Ezzaral: Added code tags. Please use them to format any code that you post.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.