Jump to content

Showing Results While Loop Continues....?


EmperorJazzy

Recommended Posts

So I have 2 queries, that has the potential to return alot of data, foreach loops running. The first shows each group heading, and the foreach nested is calling another query specific to the group heading. The result currently is a lengthy delay in results showing. (Now this may/may not be the most ideal code practise in this instance however... short term solution discussion please).

 

For Each State

  Read Each States Details from DB

  For Each State Listing

      Display Details

  Next

Next

 

Is there a command or other where I can say, Display HTML page as it stands while it continues to process the FOREACH loops?

 

EG:

 

For Each State

  Read Each States Details from DB

  For Each State Listing

      Display Details

      REFRESH HTML DISPLAYED

  Next

Next

Link to comment
Share on other sites

Now this may/may not be the most ideal code practise in this instance however... short term solution discussion please

 

Ideally you would use a single query and a JOIN to get the data you need.  You would do your headings by tracking the value of the field used for the header and only output the code for a header if it changes.  Switching to this single query method would likely result in a considerable speed-increase of your page.  Executing multiple select queries in a loop as you described is one of the biggest performance no-nos you can do.

 

 

Is there a command or other where I can say, Display HTML page as it stands while it continues to process the FOREACH loops?

 

You can use ob_flush and flush to clear out PHP's buffers and send the data.  Whether that makes it all the way to the browser and gets rendered is a whole different story that you cannot control though.  There may be other buffers such as a proxy server or the browsers internal render buffer.

 

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.