Jump to content

What have i done wrong here ?


ady01

Recommended Posts

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.