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>