I am wondering how to wait a certain amount of time before loading a part of a page for example: <?php echo "<img src=headerimg.gif>; echo "loading please wait..."; //wait specified time before loading below include("restofpage.php"); Code (markup): any help would be appriciated thank you
What you could do is have the delayed content in a <div> and write the html into it after a certain period of time using javascript. Do a google search for: Javascript Timeout (delay) Javascript change div content. That should help you out. Working on it yourself with some research should help you understand the code. Or you could try this: (untested as i'm sitting in college right now). <?php echo "<img src=headerimg.gif>; echo "loading please wait..."; //wait specified time before loading below ?> <div id="DIVID" style="visibility: hidden"><?include("restofpage.php");?></div> <script language="JavaScript"> setTimeout("DIVID.style.visibility='visible'",5000); </script> Code (markup):
Thank you thats what I was looking for ... I really don't want the code but what to look for .... perfect thank you
Okay I found the sleep function which seems to do what I need using php and avoiding javascript. PROBLEM: the entire page is waiting the specified time instead of just whats after the sleep function .... any thoughts? <?php include("header.php"); ?> <?php sleep(10); ?> <table width="750" border="0" cellpadding="0" cellspacing="0"> <tr> <td width="188" align="center"><form method="post" action="newquote.php"><input type="submit" value="New Quote"></form></td> <td width="187" align="center"><form method="post" action="editquote.php"><input type="submit" value="Edit Quote"></form></td> <td width="187" align="center"><form method="post" action="copyquote.php"><input type="submit" value="Copy Quote"></form></td> <td width="188" align="center"><form method="post" action="deletequote.php"><input type="submit" value="Delete Quote"></form></td> </tr> </table> <?php include("footer.php"); ?> Code (markup): I know I don't need all the starts and stops in the php / html but i figure it might be easier to read this way
PHP is executed on the server side, which means the process on the server will sleep before continuing. After it's finished processing, it will display the output to the client side. If you want the client side to see a section of the page loaded and then delayed, you will have to do it with javascript. I hope that makes sense. Regards
Yes thank you I misunderstood the sleep function when I was looking at it at php.net. I thought it would load a certain part of the page and then when it hit the sleep thats when it would begin the wait. I suppose I need to learn Javascript Thank you for your responses.
okay the code way above seems to work visibly the only issue that I have with it now is that it only hides it from view but still seems to run the code that it waits to show in the background. <?php echo "<img src=headerimg.gif>; echo "loading please wait..."; //wait specified time before loading below ?> <div id="DIVID" style="visibility: hidden"><?include("restofpage.php");?></div> <script language="JavaScript"> setTimeout("DIVID.style.visibility='visible'",5000); </script> Code (markup): If restofpage.php has a script within it that makes changes to a database how would this db transaction be postponed for the set amount of time? (If a page is left to quickly or refreshed before the specified time I don't want it to run the script on restofpage.php at all) Again thank you for everyones responses