ady01 Posted May 10, 2008 Share Posted May 10, 2008 As part of my website i want to be able to allow mysql table to be downloaded to excel I have the below code to 'get' the data : <?php require_once("config.php"); $db=mysql_connect($AddressBook_HOST,$AddressBook_Username,$AddressBook_Password); mysql_select_db($AddressBook_DatabaseName,$db); $query = "SELECT Name, DOB, HouseNumber FROM Addresses"; $result = mysql_query($query) or die('Error, query failed'); while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { echo "Name :{$row['Name']} <br" . "DOB : {$row['DOB']} <br" . "HouseNumber : {$row['HouseNumber']} <br><br>"; } mysql_free_result($result); include 'close.php'; ?> The below code then takes the data and allows to be converted to excel: <?php include 'download.php'; $query = "SELECT Name, DOB, HoseNumber FROM Addresses"; $result = mysql_query($query) or die('Error, query failed'); $tsv = array(); $html = array(); while($row = mysql_fetch_array($result, MYSQL_NUM)) { $tsv[] = implode("\t", $row); $html[] = "<tr><td>" .implode("</td><td>", $row) . "</td></tr>"; } $tsv = implode("\r\n", $tsv); $html = "<table>" . implode("\r\n", $html) . "</table>"; $fileName = 'mysql-to-excel.xls'; header("Content-type: application/vnd.ms-excel"); header("Content-Disposition: attachment; filename=$fileName"); echo $tsv; //echo $html; include 'download.php'; ?> My problem is that the table duplicates over and over then after a few seconds get the below error ? Fatal error: Allowed memory size of 16777216 bytes exhausted (tried to allocate 11520 bytes) in /data/members/paid/a/d/webstiteaddress/htdocs/smb1buddylist/close.php on line 27 Link to comment https://forums.phpfreaks.com/topic/105009-what-have-i-done-wrong-here/ Share on other sites More sharing options...
ady01 Posted May 10, 2008 Author Share Posted May 10, 2008 Found the problem with it 'looping' the data so have stopped the error however its now just giveing the below in HTML instread on excel :: Name :522380 Name :358225 Error, query failed Link to comment https://forums.phpfreaks.com/topic/105009-what-have-i-done-wrong-here/#findComment-537495 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/105009-what-have-i-done-wrong-here/#findComment-537534 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.