I have a code here to generate an excel file if the submit button is clicked. The file is populated with data from mysql and of course is based from a mysql query. Here it is:
<?php
require("aacfs.php");
header("Content-type: application/ms-excel");
header("Content-Disposition: attachment; filename=Reservation Summary_sortbydate.xls");
header("Pragma: no-cache");
header("Expires: 0");
$head1="Ayala Aviation Corporation";
$head2="RESERVATION SUMMARY";
$head3="For the period ___________";
$heads="$head1\n$head2\n$head3\n";
$query = "select bdate as 'Date', cliename as 'Client', grpcode as 'Group Code', bperson as 'Contact', reservno as 'Reservation No.', acode as 'Aircraft', fdate as 'Flight Date', itinerary as 'Itinerary', etd as 'ETD', eta as 'ETA', pname as 'Passengers', status as 'Status', cutoff as 'Confirmation Cut-off', adminid as 'Reserved by' from reservation order by bdate";
$result = mysql_query($query);
if($result) {
$count = mysql_num_rows($result);
for($i=0; $i<$count; $i++) {
for ($i = 0; $i < mysql_num_fields($result); $i++)
{
$schema_insert_rows.=mysql_field_name($result,$i) . "\t";
}
$schema_insert_rows.="\n";
while($row = mysql_fetch_row($result)) {
$line = '';
foreach($row as $value) {
if((!isset($value)) OR ($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 = "\n(0) Records Found!\n";
}
}
print mb_convert_encoding("$heads\n$schema_insert_rows\n$data", 'UTF-16LE', 'UTF-8');
} else die(mysql_error());
?>
It takes long for it to execute and when it is finally downloaded on my computer, the file displays an error message: 'Maximum execution time of 60 seconds exceeded'. I tried setting the time limit like this: set_time_limit(0)
but it still take a long time before I can get to download the file and when I opened the downloaded file, another error displays again on the file itself: 'Allowed memory size of 134217728 bytes exhausted (tried to allocate 133693422 bytes)'
I have this exact code but different mysql_query running on another php file so I'm really frustated as to why this doesn't work. I have this working smoothly the other day but when I checked it again today, it shows this error. What am I doing wrong? Any help would be appreciated. Thank you in advance! GOD bless!