Building html tables from query data... faster?

Posted by Andrew Heath on Stack Overflow See other posts from Stack Overflow or by Andrew Heath
Published on 2010-04-07T06:20:43Z Indexed on 2010/04/07 7:23 UTC
Read the original article Hit count: 282

Filed under:
|
|
|

With my limited experience/knowledge I am using the following structure to generate HTML tables on the fly from MySQL queries:

$c = 0;
$t = count($results);

$table = '<table>';

while ($c < $t) {
   $table .= "<tr><td>$results[0]</td><td>$results[1]</td> (etc etc) </tr>";
   ++$c;
}

$table .= '</table>';

this works, obviously. But for tables with 300+ rows there is a noticeable delay in pageload while the script builds the table. Currently the maximum results list is only about 1,100 rows, and the wait isn't long, but there's clearly a wait.

Are there other methods for outputting an HTML table that are faster than my WHILE loop? (PHP only please...)

© Stack Overflow or respective owner

Related posts about php

Related posts about loop