Well I have tried many things to get this working and am completley stuck - I want to take my data from MySQL and download it to excel format using php on my website - This is the code i have but its outputting to the browser window & not excel as i want, can anyone help as to why this s not working for me ?
<?php
include("config.php");
mysql_connect($AddressBook_HOST, $AddressBook_Username, $AddressBook_Password) or die ("Can't connect!");
mysql_select_db($AddressBook_DatabaseName) or die ("Can't open database!");
$XML = "ID,Name,DOB,HouseNumber,Street,City,Country,Telephone,Fax,Email,Remarks\n";
$file ="report_". date("Y-m-d"). ".txt";
$query = "SELECT * FROM Addresses ORDER by ID ASC";
$result = mysql_query($query) or die("Error: ". mysql_error(). " with query ". $query);
while($myrow = mysql_fetch_array($result)) {
$XML.= $myrow[ID]. "\t";
$XML.= $myrow[Name]. "\t";
$XML.= $myrow[DOB]. "\t";
$XML.= $myrow[HouseNumber]. "\t";
$XML.= $myrow[Street]. "\t";
$XML.= $myrow[City]. "\t";
$XML.= $myrow[Country]. "\t";
$XML.= $myrow[Telephone]. "\t";
$XML.= $myrow[Fax]. "\t";
$XML.= $myrow[Email]. "\t";
$XML.= $myrow[Remarks]. "\n";
}
header("Content-type: application/octet-stream");
header("Content-Disposition: attachment; filename=\"$file\"");
header("Content-Transfer-Encoding: binary");
if(strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE')){
header('Cache-Control: public');
}
echo $XML;
exit;
?>
There are no errors comming up when its run, but it out puts the below to the browser window : (the data below is just test data inserted into Mysql)
ID,Name,DOB,HouseNumber,Street,City,Country,Telephone,Fax,Email,Remarks 50 522380 Ptechnology group alivemore tgoater tgoater@example.com example example Joanne A jahern@example.com None 51 358225 eservices person a Person 1 example@example.com example example Robert Rd@example.com Place order Via EDI link 54 test test test test test test test test test testing server 57 new new new new new new new new new new testing