I have an export that I use, here is the code, it might point you in the right direction:
<?php
include("variables.php");
$link_id = mysql_connect("$db_host","$db_user","$db_password");
if (mysql_select_db("$db_database", $link_id));
else
{
echo "connection failed.";
}
$select = "SELECT club_nr, first_name, surname, email, address1, address2, postcode, town, province, phone FROM members";
$export = mysql_query($select);
$fields = mysql_num_fields($export);
for ($i = 0; $i < $fields; $i++) {
$header .= mysql_field_name($export, $i) . "\t";
}
while($row = mysql_fetch_row($export)) {
$line = '';
foreach($row as $value) {
if ((!isset($value)) OR ($value == "")) {
$value = " \t";
} else {
$value=stripcslashes($value);
$value = str_replace('"', '""', $value);
$value = '"' . $value . '"' . "\t";
}
$line .= $value;
}
$data .= trim($line)."\n";
}
$data = str_replace("\r","",$data);
if ($data == "") {
$data = "\n(0) Records Found!\n";
}
header("Content-type: application/x-msdownload");
header("Content-Disposition: attachment; filename=bridge_club_members.xls");
header("Pragma: no-cache");
header("Expires: 0");
print "$header\n$data";
?>