Jump to content

echo'ing large php variables


pagegen

Recommended Posts

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.