ady01 Posted May 10, 2008 Share Posted May 10, 2008 I have written the below to download my data from MySQL to excel format however all it does is display my error 'SQL table is empty, no data to display. Please add entries to database before using the download function' Any idears why this is not working for me ? <?php include('config.php'); $db=mysql_connect($AddressBook_HOST,$AddressBook_Username,$AddressBook_Password); mysql_select_db($AddressBook_DatabaseName,$db); $result = mysql_query('select * from Addresses', $linkID); $count = mysql_num_fields($result); for ($i = 0; $i < $count; $i++){ $header .= mysql_field_name($result, $i)."\t"; } while($row = mysql_fetch_row($result)){ $line = ''; foreach($row as $value){ if(!isset($value) || $value == ""){ $value = "\t"; }else{ $value = str_replace('"', '""', $value); $value = '"' . $value . '"' . "\t"; } $line .= $value; } $data .= trim($line)."\n"; } $data = str_replace("\r", "", $data); if ($data == "") { $data = "\nSQL table is empty, no data to display. Please add entries to database before using the download function\n"; } header("Content-type: application/octet-stream"); header("Content-Disposition: attachment; filename=buddylist.xls"); header("Pragma: no-cache"); header("Expires: 0"); echo $header."\n".$data; ?> Link to comment https://forums.phpfreaks.com/topic/105025-table-to-excel-not-working/ Share on other sites More sharing options...
BlueSkyIS Posted May 10, 2008 Share Posted May 10, 2008 update: $result = mysql_query('select * from Addresses') or die(mysql_error()); Link to comment https://forums.phpfreaks.com/topic/105025-table-to-excel-not-working/#findComment-537646 Share on other sites More sharing options...
ady01 Posted May 10, 2008 Author Share Posted May 10, 2008 That seems to have sorted the error however the dat is now comming out all skew wiff - the below is what im getting in html not downloading to excel like i want ? ID Name DOB HouseNumber Street City Country Telephone Fax Email Remarks "50" "522380" "Ptechnology group" "alivemore" "tgoater" "[email protected]" "example" "example" "Joanne A" "[email protected]" "None" "51" "358225" "eservices" "person a" "Person 1" "[email protected]" "example" "example" "Robert" "[email protected]" "Place order Via EDI link" Link to comment https://forums.phpfreaks.com/topic/105025-table-to-excel-not-working/#findComment-537769 Share on other sites More sharing options...
Barand Posted May 10, 2008 Share Posted May 10, 2008 End the rows with "\r\n" Link to comment https://forums.phpfreaks.com/topic/105025-table-to-excel-not-working/#findComment-537785 Share on other sites More sharing options...
ady01 Posted May 10, 2008 Author Share Posted May 10, 2008 Sorry to sound dumb but which ones do you mean . ? Link to comment https://forums.phpfreaks.com/topic/105025-table-to-excel-not-working/#findComment-537832 Share on other sites More sharing options...
ady01 Posted May 10, 2008 Author Share Posted May 10, 2008 **bump** Link to comment https://forums.phpfreaks.com/topic/105025-table-to-excel-not-working/#findComment-537853 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.