Page 1 of 1
How do you show HTML 'waiting' BEFORE DB Query is complete?
Posted: Fri Feb 19, 2010 8:06 am
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.
Re: How do you show HTML 'waiting' BEFORE DB Query is complete?
Posted: Fri Feb 19, 2010 8:13 am
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
Re: How do you show HTML 'waiting' BEFORE DB Query is complete?
Posted: Fri Feb 19, 2010 10:08 am
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.
Re: How do you show HTML 'waiting' BEFORE DB Query is complete?
Posted: Fri Feb 19, 2010 12:42 pm
by simonmlewis
Thanks, but how do you update the page to say "processing" and for that to disappear when it is finished processing?
Re: How do you show HTML 'waiting' BEFORE DB Query is complete?
Posted: Fri Feb 19, 2010 1:51 pm
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.
Re: How do you show HTML 'waiting' BEFORE DB Query is complete?
Posted: Fri Feb 19, 2010 2:07 pm
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?
Re: How do you show HTML 'waiting' BEFORE DB Query is complete?
Posted: Fri Feb 19, 2010 3:15 pm
by pickle
Do some research into how you can use Javascript to
- Listen for the submit() event of a form
- 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.
Re: How do you show HTML 'waiting' BEFORE DB Query is complete?
Posted: Fri Feb 19, 2010 6:32 pm
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