Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Form to PHP script reqs. 'please wait' page

Status
Not open for further replies.

SM777

Technical User
Mar 7, 2001
208
GB
I have a form which passes data to a database scanning script. How do I create a 'please wait while the records are retrieved' kind of pre page before the results are displayed?

1. user fills in form presses submit
2. vars passed to database.php
3. database.php displays 'please wait'
4. database.php scans database and gathers report
5. database.php clears screen and displays report.

I'm not interested in snazzy progress bars, just a static page will do.

 
Why not simply use some plain HTML:

<html>
<head>
<meta http-equiv=&quot;refresh&quot; content=&quot;5;URL=database.php?action=show_result&quot;>
</head>
<body>
One moment please.....
</body>
</html>

Quasibobo Don't eat yellow snow!
 
How does it know when the script has finished searching the database? Some of the searches take miliseconds, some 15 !



 
There is no truly good way to solve this problem with HTTP/HTML. That's because these technologies were never meant to solve that problem. HTTP is a stateless protocol, so it only lives by responding to user requests. It can't just send a &quot;request&quot; of it's own to the browser whenever it wants.

There are 3 possible workarounds, at varying levels of complexity:

1. The simplest approach might be to just take Quasibobo's suggestion, but set the refresh at 1 second. Then the page keeps on refreshing, and whenever the results are available, they load instead of the refreshing page. I know you want better than 1 second resolution, but really, just about any web page takes at least a second to load, so it's not such a bad way to go.

2. With a hidden frame, you can hide the page that actually does the refreshing. Just use a bit of javascript in the hidden refreshing page to trigger a load of the main page when the results are ready.

3. Certain webservers (and most recent browsers) allow for partial loading of HTML, while keeping the HTTP connection open and idling until the rest of the data appears. With this in mind, you would use PHP's flush() function ( to output the &quot;wait&quot; message to the browser right away, and then keep the HTTP connection open until the rest of the data is received and printed. Bear in mind that PHP defaults to a maximum execution time of 30 seconds per script, unless you change the php.ini settings, or make a run-time configuration change for that script. -------------------------------------------

Big Brother: &quot;War is Peace&quot; -- Big Business: &quot;Suspicion is Trust&quot;
(
 
OK, option 3 sounds worth investigating.

One other thing which may help solve this problem. I've asked this question before but was told it cant be done - sending the results of php script to a popup window.

1. user fills in .html form
2. a pop up window opens and runs database.php
3. database.php gathers report
4. database.php displays results

Could this work with a processing message?

2(a) pop up window displays 'processing...'

The problem I seem to remember was that the database.php in the popup (javascript) windows could not read the vars from the .html unless I used sessions or cookies. I'm trying to keep it simple with no sessions or cookies so I was unable to do it.

What about Perl? Would that be better at using a &quot;processing ...&quot; and a popup results page?

Cheers guys.
 
id go with rycamor- using a bit of javascript as well..

have the user redirected straight to the database.php page, where it immediately outputs &quot;please wait&quot; in a named div or somesuch, then flush it out to the user.. Immediately after the flush, put in a bit of javascript which hides the div, and after that just display the results of the page. Therefore as soon as the script finishes, the javascript will be sent to the browser, hiding the div with Please Wait in it, and the results will be shown!
 
>>The problem I seem to remember was that the database.php in the popup (javascript) windows could not read the vars from the .html unless I used sessions or cookies. I'm trying to keep it simple with no sessions or cookies so I was unable to do it.

You don't need sessions or cookies, but if you want a pop-up window, you will have to dynamically make all the incoming POST variables from the parent page available to the pop-up. One way to do this is to urlencode() each value and place it on the query string for the pop-up definition:

Code:
<script language=&quot;javascript&quot;>

window.open(&quot;<?php 
echo: '
popup.php?var1=' . 
unrlencode($var1) . 
'&var2=' . 
urlencode($var2) . 
//etc... for all posted vars
?>&quot;);

</script>

This would replicate all the posted variables to the popup window, allowing PHP to use them as $_GET vars.

>>What about Perl? Would that be better at using a &quot;processing ...&quot; and a popup results page?

Perl, PHP, ASP... it doesn'n matter. The real problem is in the client and the protocol, rather than the server. A better knowladge of Javascript will be the most helpful thing in your case. -------------------------------------------

Big Brother: &quot;War is Peace&quot; -- Big Business: &quot;Suspicion is Trust&quot;
(
 
I had a similar problem with a PDF gen, I used the following:

echo &quot;<HTML><BODY>Creating printout, please wait...&quot;;
echo str_repeat(&quot; &quot;, 300); //This clears buffers!

Then when my script had finished, I forwarded them onto the PDF with javascript.

echo &quot;<script>location.href = './cache/&quot;.$this->_FileName.&quot;';</script></body></html>&quot;;

Hope this helps --BB
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top