Page 1 of 1
Please Wait Message
Posted: Wed Sep 03, 2003 4:25 am
by RedRasper
Hi,
I have a php script which runs a query that takes ages to run, so I'd like to tell the user to "please wait"
I've tried putting a message in and echoing it out before the query, but nothing gets displayed until the query is run.
Can anyone help?
Many thanks
RedRasper
Posted: Wed Sep 03, 2003 4:35 am
by JayBird
i think this might be some use
http://se.php.net/manual/en/function.flush.php
basically, it "flushes" all output so far to the broswer. So placing it after the echo command should work.
You may need more help with this cos certain browers have certain problem doing this.
Make sure you read all the notes on the link i gave you.
Mark
Posted: Wed Sep 03, 2003 5:31 am
by RedRasper
Hi,
thanks for the reply, that looks like its going to get some output. I'm going to play with that now.
Just a slight modification on the question though, can I have a loading page saying "executing query" then when that has finished clear that off the screen and display the query results?
Many thanks
RedRasper
Posted: Wed Sep 03, 2003 5:34 am
by JayBird
Yes that is possible.
Don't know if you have ever used Streamload (
http://www.streamload.com), but the thing you are describing happens on that site!
I think it is done using <div> tags and CSS.
Not 100% sure though.
Posted: Wed Sep 03, 2003 5:41 am
by RedRasper
Hi,
thanks for the quick reply, I'll look at that. Acutally when you mentioned css and div I do seem to recall that you can dynamically hide elements which I might look at too!
Cheers for your help,
RedRasper
Posted: Wed Sep 03, 2003 5:45 am
by JayBird
**Removed due to errors in scripts**
Posted: Wed Sep 03, 2003 5:55 am
by RedRasper
Hi,
Will give it go now, and let you know!
RedRasper
Posted: Wed Sep 03, 2003 5:58 am
by JayBird
ignore my previous post, i didn't work, i have now refined it.
Try this fully working example (save the file with a .php extension)
Code: Select all
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script language=JavaScript>
function getPageItem(itemID)
{
if (document.getElementById)
{
return document.getElementById(itemID);
}
if (document.all)
{
return document.allїitemID];
}
return null;
}
<!--
function slUpdateSpan(newHtml)
{
var span_obj = getPageItem("idUpdateableSpan");
if (span_obj)
{
if (span_obj.style.display != "inline")
{
span_obj.style.display = "inline";
}
span_obj.innerHTML = newHtml;
}
}
function killUpdateSpan()
{
var span_obj = getPageItem("idUpdateableSpan");
if (span_obj)
{
span_obj.style.display = "none";
}
}
//-->
</script>
</head>
<body>
<div id="idUpdateableSpan"
style="position: absolute;
top: 40%; left: 35%;
width: 30%;
height: 80px;
filter:alpha(opacity=80);
-moz-opacity:80%;
margin:0;
padding:15px;
background-color:#eee;
border:1px solid #333;
text-align: center;
z-index:1000;
display:none;
cursor:default;
"></div>
<script language=JavaScript>
<!--
slUpdateSpan("Yawning...<br><br>");
//-->
</script>
<? flush(); sleep(5); ?>
<script language=Javascript>
<!--
killUpdateSpan();
//-->
</script>
</body>
</html>
Mark
Posted: Wed Sep 03, 2003 6:02 am
by JayBird
now, all you have to do it replace the sleep(5); with the MySQL query that is taking ages.
Should work a treat

)
Mark
Posted: Wed Sep 03, 2003 6:27 am
by JayBird
you can also change the message at different stages
Save this code with a .php extension
Code: Select all
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script language=JavaScript>
function getPageItem(itemID)
{
if (document.getElementById)
{
return document.getElementById(itemID);
}
if (document.all)
{
return document.allїitemID];
}
return null;
}
<!--
function slUpdateSpan(newHtml)
{
var span_obj = getPageItem("idUpdateableSpan");
if (span_obj)
{
if (span_obj.style.display != "inline")
{
span_obj.style.display = "inline";
}
span_obj.innerHTML = newHtml;
}
}
function killUpdateSpan()
{
var span_obj = getPageItem("idUpdateableSpan");
if (span_obj)
{
span_obj.style.display = "none";
}
}
//-->
</script>
</head>
<body>
<div id="idUpdateableSpan"
style="position: absolute;
top: 40%; left: 35%;
width: 30%;
height: 80px;
filter:alpha(opacity=80);
-moz-opacity:80%;
margin:0;
padding:15px;
background-color:#eee;
border:1px solid #333;
text-align: center;
z-index:1000;
display:none;
cursor:default;
"></div>
<script language=JavaScript>
<!--
slUpdateSpan("Yawning...<br><br>");
//-->
</script>
<? flush(); sleep(5); ?>
<script language=JavaScript>
<!--
slUpdateSpan("Preparing to continue...<br><br>");
//-->
</script>
<? flush(); sleep(5); ?>
<script language=Javascript>
<!--
killUpdateSpan();
//-->
</script>
</body>
</html>
Mark
Posted: Wed Sep 03, 2003 6:33 am
by RedRasper
Hi,
Wow, thats great, works really well! Very impressed with it!
That flush does prove difficult on some browsers as you said, I'm looking at that now! Works great in ie 6 though!
Many thanks for all your help and time, its very much appreciated!
RedRasper
Posted: Wed Sep 03, 2003 8:32 am
by JayBird
another variation if you are interested.
Again, just save the script with a .php extension
Code: Select all
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script language=JavaScript>
function getPageItem(itemID) {
if (document.getElementById) {
return document.getElementById(itemID);
}
if (document.all) {
return document.allїitemID];
}
return null;
}
<!--
function slUpdateSpan(newHtml) {
var span_obj = getPageItem("idUpdateableSpan");
if (span_obj) {
if (span_obj.style.display != "inline") {
span_obj.style.display = "inline";
}
span_obj.innerHTML = newHtml;
}
}
function killUpdateSpan() {
var span_obj = getPageItem("idUpdateableSpan");
if (span_obj) {
span_obj.style.display = "none";
}
}
//-->
</script>
</head>
<body>
<div id="idUpdateableSpan"
style="position: absolute;
top: 40%; left: 35%;
width: 30%;
height: 80px;
filter:alpha(opacity=80);
-moz-opacity:80%;
margin:0;
padding:15px;
background-color:#eee;
border:1px solid #333;
text-align: center;
z-index:1000;
display:none;
cursor:default;
"></div>
<script language=JavaScript>
<!--
slUpdateSpan("Yawning...<br><br>");
//-->
</script>
<? flush(); sleep(5); ?>
<?
$i = 0;
while ($i < 10) {
echo "<script language=JavaScript>\n";
echo "<!--\n";
echo " slUpdateSpan("Putting the cat out".str_repeat(".", $i)."<br><br>");\n";
echo "//-->\n";
echo "</script>\n";
flush(); sleep(1);
$i++;
}
?>
<script language=Javascript>
<!--
killUpdateSpan();
//-->
</script>
</body>
</html>