wait before loading part of page?

Discussion in 'PHP' started by mokimofiki, Sep 9, 2008.

  1. #1
    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 :)
     
    mokimofiki, Sep 9, 2008 IP
  2. nabz245

    nabz245 Well-Known Member

    Messages:
    677
    Likes Received:
    18
    Best Answers:
    0
    Trophy Points:
    110
    #2
    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):
     
    nabz245, Sep 9, 2008 IP
  3. mokimofiki

    mokimofiki Well-Known Member

    Messages:
    444
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    130
    #3
    Thank you thats what I was looking for ... I really don't want the code but what to look for .... perfect thank you
     
    mokimofiki, Sep 9, 2008 IP
  4. mokimofiki

    mokimofiki Well-Known Member

    Messages:
    444
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    130
    #4
    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 :)
     
    mokimofiki, Sep 9, 2008 IP
  5. nabz245

    nabz245 Well-Known Member

    Messages:
    677
    Likes Received:
    18
    Best Answers:
    0
    Trophy Points:
    110
    #5
    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
     
    nabz245, Sep 9, 2008 IP
  6. mokimofiki

    mokimofiki Well-Known Member

    Messages:
    444
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    130
    #6
    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.
     
    mokimofiki, Sep 10, 2008 IP
  7. hip_hop_x

    hip_hop_x Active Member

    Messages:
    522
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    90
    #7
    no the sleep doesn't do that, javascript/ajax will be required for this kind of process
     
    hip_hop_x, Sep 10, 2008 IP
  8. harsh789

    harsh789 Member

    Messages:
    29
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    38
    #8
    Try using flush() function before you using sleep() in your code. I am not sure but this might help.
     
    harsh789, Sep 10, 2008 IP
  9. mokimofiki

    mokimofiki Well-Known Member

    Messages:
    444
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    130
    #9
    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 :)
     
    mokimofiki, Sep 10, 2008 IP