How do you show HTML 'waiting' BEFORE DB Query is complete?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

How do you show HTML 'waiting' BEFORE DB Query is complete?

Post by simonmlewis »

We have a page that is going to take about a minute or less to run a query and check various database stock levels.

While it's waiting and loading, is there a way to show a bit of text or image - basically echo ""; some content BEFORE the query is complete?

Regards
S.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
User avatar
Eran
DevNet Master
Posts: 3549
Joined: Fri Jan 18, 2008 12:36 am
Location: Israel, ME

Re: How do you show HTML 'waiting' BEFORE DB Query is complete?

Post by Eran »

You can do it in two ways -
1. flush the output buffer using flush() (and ob_flush() as necessary, read the description in the manual) to send output before the script has finished executing (ie, before you run the query)
2. Send an AJAX refresh after the page has loaded

If possible, it would be better to improve the performance of the queries / processes involved
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: How do you show HTML 'waiting' BEFORE DB Query is complete?

Post by pickle »

In my experience, flushing doesn't always work. Since browsers generally show the current page while waiting for the new page to be generated & sent, I update the current page to say "Processing" or whatever.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Re: How do you show HTML 'waiting' BEFORE DB Query is complete?

Post by simonmlewis »

Thanks, but how do you update the page to say "processing" and for that to disappear when it is finished processing?
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: How do you show HTML 'waiting' BEFORE DB Query is complete?

Post by pickle »

I'm assuming you're submitting a form, and once the query is done, the page reloads.

You can use Javascript to put the words on the page before the form gets submitted, or make a hidden div appear, or however else you want to do it. Once the page reloads after the query is done, it's a different page so the "Processing" message shouldn't appear.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Re: How do you show HTML 'waiting' BEFORE DB Query is complete?

Post by simonmlewis »

Very good idea, but I am not a Javascript writer. I can find them, and sometimes modify them. But sadly I cannot write Javascript from scratch.

Also not sure how Javascript would even be able to identify if a Query was completed?
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: How do you show HTML 'waiting' BEFORE DB Query is complete?

Post by pickle »

Do some research into how you can use Javascript to
  1. Listen for the submit() event of a form
  2. Make an hidden element appear on the page.
As I've tried to explain before, in this process, you'll have 2 different page loads. The first that shows the empty form to the user, and the second that shows the page after the query is done. The Javascript would only work on the first page - making "Processing" show up when the form was submitted. Once the query is done, the second page loads and the first page goes away.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
mikosiko
Forum Regular
Posts: 757
Joined: Wed Jan 13, 2010 7:22 pm

Re: How do you show HTML 'waiting' BEFORE DB Query is complete?

Post by mikosiko »

simonmlewis wrote:Very good idea, but I am not a Javascript writer. I can find them, and sometimes modify them. But sadly I cannot write Javascript from scratch.

Also not sure how Javascript would even be able to identify if a Query was completed?
Use Ajax...

here is and example that you can read and with minors modifications incorporate to your page
http://www.w3schools.com/ajax/ajax_example.asp
Post Reply