Reputation: 19
I am working on optimization of a php/mysql web application . The problem which I am facing is that the result of a function is really big ! like 4MB.
I call a function inside HTML-php file :
<table id="example1" class="table table-bordered table-striped table-hover" width="100%">
<thead>
<tr><th>
.
.
.</thead>
<?php
$results = $diosAdminMain->getResults();
echo $results;
?>
</table>
and should get the results from my DB and then present them with help of Datatables.
inside my class file is my function
<?php
$diosAdminMain = new diosCore;
class diosCore{
public function getResults(){
$myhtml='<tbody>';
.
.
.
$resultqry=mysql_query('SELECT * from table');
while($row = mysql_fetch_assoc($resultqry)){
$myhtml.= '<tr>
<td>'.$row['ID'].'</td>
<td>'.$row['PR1'].'</td>
<td>'.$row['PR2'].'</td>
<td>'.$row['THL1'].'</td>
<td>'.$row['THL2'].'</td>
<td>'.$row['NAME1'].'</td>
<td>'.$row['NAME2'].'</td>';
}
$myhtml.='</tbody>';
return $myhtml;
}
}
.
.
?>
I try to figure out a way to make make this presentation faster because the results are going to grow more. Now for 1800 rows ,takes almost 20 secs to show on chrome.
By the measurements I took without the datatables it only saves me 1-2 secs( and I don't want to remove it as the fast search is awsome). I also tried to optimise the mysql queries and the logical flow inside function but the same result. So I exported the result of the function as a plain text and found out that is just a big result with 4MB size.
Is there a way to suppress somehow the size of the $myhtml variable to make things faster ? or any other way I missed ?
thanks
Upvotes: 1
Views: 181
Reputation: 370
You should consider showing the results page by page. It is not possible to show a huge amount of data into a page without a performance impact. Showing 50 or a 100 rows per page will be much faster and will work with all amounts of data.
Upvotes: 1