Hi there, well, I’m trying to export mysql data to excel, I found a script, but when I tryed to access that php document there’s a message error:
Warning: Cannot modify header information - headers already sent by (output started at /Library/WebServer/Documents/doug/excel.php:10) in /Library/WebServer/Documents/doug/excel.php on line 46
Warning: Cannot modify header information - headers already sent by (output started at /Library/WebServer/Documents/doug/excel.php:10) in /Library/WebServer/Documents/doug/excel.php on line 47
Warning: Cannot modify header information - headers already sent by (output started at /Library/WebServer/Documents/doug/excel.php:10) in /Library/WebServer/Documents/doug/excel.php on line **48
**I don’t know what’s wrong, so, here’s my script:
<?php
define(db_host, "localhost");
define(db_user, "root");
define(db_pass, "");
define(db_link, mysql_connect(db_host,db_user,db_pass));
define(db_name, "restaurant");
mysql_select_db(db_name);
?>
<?php
$select = "SELECT * FROM maintable";
$export = mysql_query($select);
$fields = mysql_num_fields($export);
?>
<?php
for ($i = 0; $i < $fields; $i++) {
$header .= mysql_field_name($export, $i) . " ";
}
?>
<?php
while($row = mysql_fetch_row($export)) {
$line = '';
foreach($row as $value) {
if ((!isset($value)) OR ($value == "")) {
$value = " ";
} else {
$value = str_replace('"', '""', $value);
$value = '"' . $value . '"' . " ";
}
$line .= $value;
}
$data .= trim($line)."
";
}
$data = str_replace("\r","",$data);
?>
<?php
if ($data == "") {
$data = "
(0) Records Found!
";
}
?>
<?php
header("Content-type: application/x-msdownload");
header("Content-Disposition: attachment; filename=Restaurants.xls");
header("Pragma: no-cache");
header("Expires: 0");
print "$header
$data";
?>
can somebody here help me please?
Thanks a lot!!