Hi! I have a php code that generates an excel file that is populated with mysql data of course through 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 LIMIT 15";
$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());
?>
This works perfectly but as you can see, I have put a limit on my query.. LIMIT 15
. Why? Because if I don't, the downloading of the excel file will take long and if it is finally downloaded on my computer, the file will display an error: Maximum execution time of 60 seconds exceeded
. I know what causes this error. My mysql table currently has 27 rows with 24 columns (though this data lessens with the query I have) and I think it can't fetch all that data that's why I get that error. But I really need to get those (many) data as it is required with what I should do. Do you have any ideas to allow the program to fetch as many data as it can? And also, how can I put the $heads="$head1\n$head2\n$head3\n";
in center without downloading any PHPExcel writer etc? Please help me. Thank you.