0

I have a site with a div that I want to list all currently logged in users. I set a bool in my DB where 1 means that users is logged in. I'm trying to dynamically generate the list using a jQuery AJAX call to a php page that polls the DB for all the logged in users.

The PHP code checks the DB and creates a list of all logged in users. My issue is I can't seem to get the jQuery function to load the data from the page.

<?php
   include ('settings.php');
   if ($db_found)
   {
      $sql = "SELECT * FROM $db_table WHERE logged_in='1'";
      $result = mysql_query($sql);
      $count = mysql_num_rows($result);
      // Check if the account is already in the DB
      $i = 0;
      while ($i < $count)
      {
         $online = mysql_result($result,$i,"logged_in");
         if ($online == 1)
         {
            $user = mysql_result($result,$i,"displayname");
            print "<li>$user</li>";
         }
         $i++;
      }
      mysql_close($db_handle);
   }
?>

Whats wrong with the way I used the jQuery load so the loggedin.php page content would be displayed in the #loggedin-players div?

<script type="text/javascript">
    function updatePlayerList()
    {
    $('#loggedin-players').load('loggedin.php');
    }
    $setInterval("updatePlayerList()", 5000);
</script>
0

1 Answer 1

1

There should not be a $ before setInterval

setInterval("updatePlayerList()", 5000);

Your function is never called.

Sign up to request clarification or add additional context in comments.

1 Comment

Wow got to love typos. Thanks that was it, it was driving me nuts because this was such a simple thing to do.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.