# MySQL to Excel

**URL:** <https://forum.kirupa.com/t/mysql-to-excel/179913>\
**Category:** programming\
**Created:** [February 23, 2006, 10:36pm UTC](https://forum.kirupa.com/t/mysql-to-excel/179913 "2006-02-23T22:36:06Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![arturo](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/arturo/32/761_2.png) [@arturo](https://forum.kirupa.com/u/arturo)\
**Post date:** [February 23, 2006, 10:36pm UTC](https://forum.kirupa.com/t/mysql-to-excel/179913/1 "2006-02-23T22:36:06Z")

</div>

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:

```auto

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