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

please help with code.

Recommended Answers

Please read my article on exporting to Excel in PHP here.
Let me know if that …

Jump to Post

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

$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";
$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 1.20 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.