my whole code is this:
<?php
/********************************************
This code will extract the data from your table and format
it for an excel spreadsheet download. It is very quick,
simple, and to the point. If you only want to extract
certain fields and not the whole table, simply replace
the * in the $select variable with the fields you want
to extract.
/********************************************/
// Include Server parameters
require(\'includes/configure.php\');
define(db_link, mysql_connect(DB_SERVER,DB_SERVER_USERNAME,DB_SERVER_PASSWORD));
mysql_select_db(DB_DATABASE);
//Write the query, call it, and find the number of fields
$select = "SELECT * FROM orders";
$export = mysql_query($select);
$count = mysql_num_fields($export);
//Extract field names and write them to the $header variable
for ($i = 0; $i < $count; $i++) {
$header .= mysql_field_name($export, $i)."t";
}
// Extract all data, format it, and assign to the $data variable
while($row = mysql_fetch_row($export)) {
$line = \'\';
foreach($row as $value) {
if ((!isset($value)) OR ($value == "")) {
$value = "t";
} else {
$value = str_replace(\'"\', \'""\', $value);
$value = \'"\' . $value . \'"\' . "t";
}
$line .= $value;
}
$data .= trim($line)."n";
}
$data = str_replace("r", "", $data);
//Set the default message for zero records
if ($data == "") {
$data = "n(0) Records Found!n";
}
//Set the automatic download section
header("Content-type: application/octet-stream");
header("Content-Disposition: attachment; filename=orders.xls");
header("Pragma: no-cache");
header("Expires: 0");
print "$headern$data";
?>