Please Wait Message

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
RedRasper
Forum Commoner
Posts: 48
Joined: Thu Apr 24, 2003 6:36 am

Please Wait Message

Post 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
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post 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
RedRasper
Forum Commoner
Posts: 48
Joined: Thu Apr 24, 2003 6:36 am

Post 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
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post 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.
RedRasper
Forum Commoner
Posts: 48
Joined: Thu Apr 24, 2003 6:36 am

Post 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
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

**Removed due to errors in scripts**
Last edited by JayBird on Wed Sep 03, 2003 6:35 am, edited 1 time in total.
RedRasper
Forum Commoner
Posts: 48
Joined: Thu Apr 24, 2003 6:36 am

Post by RedRasper »

Hi,

Will give it go now, and let you know!

RedRasper
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post 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)
&#123;
    if (document.getElementById)
    &#123;
        return document.getElementById(itemID);
    &#125;
    
    if (document.all)
    &#123;
        return document.all&#1111;itemID];
    &#125;

    return null;
&#125;
            <!--
            function slUpdateSpan(newHtml)
            &#123;
                var span_obj = getPageItem("idUpdateableSpan");
                if (span_obj)
                &#123;
                    if (span_obj.style.display != "inline")
                    &#123;
                        span_obj.style.display = "inline";
                    &#125;
                    span_obj.innerHTML = newHtml;
                &#125;
            &#125;
            function killUpdateSpan()
            &#123;
                var span_obj = getPageItem("idUpdateableSpan");
                if (span_obj)
                &#123;
                    span_obj.style.display = "none";
                &#125;
            &#125;
            //-->
            </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
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post 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 :o)

Mark
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post 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)
&#123;
    if (document.getElementById)
    &#123;
        return document.getElementById(itemID);
    &#125;
    
    if (document.all)
    &#123;
        return document.all&#1111;itemID];
    &#125;

    return null;
&#125;

<!--
function slUpdateSpan(newHtml)
	&#123;
	var span_obj = getPageItem("idUpdateableSpan");
                if (span_obj)
                &#123;
                    if (span_obj.style.display != "inline")
                    &#123;
                        span_obj.style.display = "inline";
                    &#125;
                    span_obj.innerHTML = newHtml;
                &#125;
            &#125;
            function killUpdateSpan()
            &#123;
                var span_obj = getPageItem("idUpdateableSpan");
                if (span_obj)
                &#123;
                    span_obj.style.display = "none";
                &#125;
            &#125;
            //-->
            </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
RedRasper
Forum Commoner
Posts: 48
Joined: Thu Apr 24, 2003 6:36 am

Post 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
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post 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) &#123;
	if (document.getElementById) &#123;
		return document.getElementById(itemID);
	&#125;
    
	if (document.all) &#123;
		return document.all&#1111;itemID];
	&#125;

	return null;

&#125;

<!--
function slUpdateSpan(newHtml) &#123;
	var span_obj = getPageItem("idUpdateableSpan");
	if (span_obj) &#123;
		if (span_obj.style.display != "inline") &#123;
			span_obj.style.display = "inline";
		&#125;
	span_obj.innerHTML = newHtml;
	&#125;
&#125;

function killUpdateSpan() &#123;
	var span_obj = getPageItem("idUpdateableSpan");
	if (span_obj) &#123;
		span_obj.style.display = "none";
	&#125;
&#125;
//-->
</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) &#123;
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++;
&#125;

?>

					
<script language=Javascript>
        <!--
        killUpdateSpan();
        //-->
</script>

</body>
</html>
Post Reply