The problem is unlikely in PHP, it is a huge amount of HTML that is displayed in the browser. You can verify this yourself by saving the page that you get, and then download the static file from your hard drive.
If you display a large table, the browser will often have problems redrawing it as the content loads. This can be minimized by setting a fixed width for all columns. Just do it on the first line.
You can also jump out of the PHP block to output most of the HTML, and then simply print the variables where necessary. Here's an example, assuming all your data is in the $rows variable:
<?php <table> <thead> <tr> <th width="50">Header 1</th> <th width="200">Header 2</th> <th width="150">Header 3</th> <th width="100">Header 4</th> </tr> </thead> <tbody> <?php foreach ( $rows as $r ) : ?> <tr> <td><?=$r['var1']?><td> <td><?=$r['var2']?><td> <td><?=$r['var3']?><td> <td><?=$r['var4']?><td> </tr> <?php endforeach; ?> </tbody> </table> <?php
Note. If you don't have short PHP tags, you need to do <?php echo $r['var1'] ?> Instead.
Finally, you can try adding gzip compression. This is best done at the server level, but in PHP you can add the string ob_start("ob_gzhandler"); like the very first line of PHP code right after <?php .
If this still does not help, then it is a simple fact that your table is too large. You will be much better off using pagination or filtering to reduce the size.
source share