pagegen Posted September 6, 2011 Share Posted September 6, 2011 Hi Guys, We are working on a PHP page which loops through several records of the database. Current code using php5, MYSQL db <?php $rs_members = mysql_query("SELECT * FROM members"); while($row_members = mysql_fetch_assoc($rs_members)){ ?> <table> <tr><td><?php echo $row_member['fname']; ?></td></tr> </table <?php } ?> One of the guys suggested passing the data to client side (am guessing to javascript) and then write to the screen to speed things up. Can someone please comment, or suggest the best way to deal with this Quote Link to comment Share on other sites More sharing options...
ManiacDan Posted September 6, 2011 Share Posted September 6, 2011 That won't speed anything up. In fact, it will slow it down. If your goal is to display all the records in this table on the same page, you're doing it the fastest way possible. It would be slightly faster to replace your table data with <br /> so that you're sending fewer characters, but not much faster. You may also want to look into pagination so you only print 100 at a time instead of the whole table (however big it is). There is also the option of flushing the output buffer. When you output data in PHP, the web server "remembers" what you're trying to send and will send it in large chunks. If you have 5,000 lines in your output, the webserver may send 1,000 at a time, 5 times. The delay between these "chunks" appears like slowness to the user. You can put this line after your echo to make the records show up faster: ob_flush();flush(); However, note that this actually slows down the site because there's a lot of extra overhead in sending a small amount of output through a system designed for an entire HTML document. -Dan Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.