Thread: Php loop help

Page 1 of 2 12 LastLast
Results 1 to 10 of 18
  1. #1 Php loop help 
    HTML5, jQuery & CSS3 Master
    Jaiden Watling's Avatar
    Join Date
    Nov 2010
    Age
    26
    Posts
    890
    Thanks given
    306
    Thanks received
    92
    Rep Power
    0
    Hey, i have this php script
    <?php
    Spoiler for "php:

    // Make a MySQL Connection
    mysql_connect("localhost", "*****", "******") or die(mysql_error());
    mysql_select_db("players") or die(mysql_error());

    //Query
    $online = mysql_query("SELECT * FROM online WHERE id = 1");

    //put the query result into a var
    $totalonline = mysql_fetch_array($online);

    //print the result

    echo "Players online: " .$totalonline['currentlyonline']."";

    ?>


    and i want to have:
    echo "Players online: " .$totalonline['currentlyonline']."";
    clear it's self and repeat every lets say, 5 seconds..
    How would i do this?

    Thanks

    I'm not good with php..

    Reply With Quote  
     

  2. #2  
    q.q


    Join Date
    Dec 2010
    Posts
    6,535
    Thanks given
    1,072
    Thanks received
    3,534
    Rep Power
    4752
    try something like

    Code:
    while(true) {
    $totalonline = mysql_fetch_array($online);
    echo "Players online: " .$totalonline['currentlyonline']."";
    sleep(5);
    }
    Reply With Quote  
     

  3. Thankful user:


  4. #3  
    HTML5, jQuery & CSS3 Master
    Jaiden Watling's Avatar
    Join Date
    Nov 2010
    Age
    26
    Posts
    890
    Thanks given
    306
    Thanks received
    92
    Rep Power
    0
    I don't think that worked actually..

    Reply With Quote  
     

  5. #4  
    HTML5, jQuery & CSS3 Master
    Jaiden Watling's Avatar
    Join Date
    Nov 2010
    Age
    26
    Posts
    890
    Thanks given
    306
    Thanks received
    92
    Rep Power
    0
    this actually made the page not load.

    Reply With Quote  
     

  6. #5  
    q.q


    Join Date
    Dec 2010
    Posts
    6,535
    Thanks given
    1,072
    Thanks received
    3,534
    Rep Power
    4752
    oh my bad, i don't actually know php very well either p:

    although i would put the sleep after the echo part
    Reply With Quote  
     

  7. #6  
    HTML5, jQuery & CSS3 Master
    Jaiden Watling's Avatar
    Join Date
    Nov 2010
    Age
    26
    Posts
    890
    Thanks given
    306
    Thanks received
    92
    Rep Power
    0
    Well, thanks for helping, even though it didn't work. i still appreciate it!

    Reply With Quote  
     

  8. #7  
    Registered Member dragonxtreme's Avatar
    Join Date
    Jan 2012
    Posts
    330
    Thanks given
    27
    Thanks received
    22
    Rep Power
    0
    u mean you want it to update users online every5 seconds instead of having to refresh? if so you could put the output page of that script into a iframe and put a refresh on the iframe so it refreshes every 5 seconds, just a non php method
    Reply With Quote  
     

  9. #8  
    Registered Member
    Join Date
    Aug 2008
    Posts
    2,420
    Thanks given
    721
    Thanks received
    595
    Rep Power
    1220
    Quote Originally Posted by Harlan View Post
    try something like

    Code:
    while(true) {
    $totalonline = mysql_fetch_array($online);
    echo "Players online: " .$totalonline['currentlyonline']."";
    sleep(5);
    }
    PHP != Java
    Quote Originally Posted by Socioscape View Post
    this actually made the page not load.
    Because it was a never ending loop, and the page doesn't show until that loop is over, which is never.
    Quote Originally Posted by dragonxtreme View Post
    u mean you want it to update users online every5 seconds instead of having to refresh? if so you could put the output page of that script into a iframe and put a refresh on the iframe so it refreshes every 5 seconds, just a non php method
    iFrames are so 1990, best would be ajax.
    [Only registered and activated users can see links. ]
    Reply With Quote  
     

  10. Thankful user:


  11. #9  
    HTML5, jQuery & CSS3 Master
    Jaiden Watling's Avatar
    Join Date
    Nov 2010
    Age
    26
    Posts
    890
    Thanks given
    306
    Thanks received
    92
    Rep Power
    0
    Quote Originally Posted by Joshua F View Post
    PHP != Java

    Because it was a never ending loop, and the page doesn't show until that loop is over, which is never.

    iFrames are so 1990, best would be ajax.
    Alright, how do you suggest i proceed then?

    Reply With Quote  
     

  12. #10  
    SERGEANT OF THE MASTER SERGEANTS MOST IMPORTANT PERSON OF EXTREME SERGEANTS TO THE MAX!

    cube's Avatar
    Join Date
    Jun 2007
    Posts
    8,881
    Thanks given
    1,854
    Thanks received
    4,741
    Rep Power
    5000
    Code:
    <div id="players">
    
    </div>
    
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>
    <script>
          setInterval(function() {
                $("#players").load('your_file.php');
          }, 5000);
    </script>



    Reply With Quote  
     

Page 1 of 2 12 LastLast

Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)


User Tag List

Similar Threads

  1. Replies: 20
    Last Post: 08-14-2010, 04:56 PM
  2. [PHP] Server Status Signature [PHP]
    By Naab in forum Website Development
    Replies: 21
    Last Post: 10-22-2009, 06:54 PM
  3. Making a php site with index.php?action=blahblahblah
    By 42 in forum Website Development
    Replies: 0
    Last Post: 04-21-2008, 07:13 AM
Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •