Display Online users in a chat application
<p>I have a chat application and in this application, i want to show online users in a chatroom. I have a database that records online users and it keeps changing whenever a new user comes. Whenever a users leaves, it is deleted from the database. Database consists of two columns: username and room. Database side works fine.</p>

<p>onlinelar.php:</p>

<pre><code>&lt;?php

$data = array();

        $current = $_GET['current'];

        $room = $_GET['room'];

        $getRoomUsers = mysql_query("SELECT * FROM `chat_users_rooms` WHERE `room` = '".$room."'");

        if(mysql_num_rows($getRoomUsers) != $current)
        {
            $data['numOfUsers'] = mysql_num_rows($getRoomUsers);    
        }
        else
        {
            $data['numOfUsers'] = $current; 
        }
        echo json_encode($data);

?&gt;
</code></pre>

<p>online.js:</p>

<pre><code>var numOfUsers = 0;
var room;

function chat(room2)
{
room = room2;   
}

$.ajaxSetup({
    cache: false 
});


function getuserlist() {


     $.ajax({
        type: "GET",
        url: "onlinelar.php",
        data: {  
                'room': room,
                'current' : numOfUsers
              },
        dataType: "json",
        cache: false,
        success: function(data) {
                if (numOfUsers != data.numOfUsers) {
                numOfUsers = data.numOfUsers;

                $('#bu').html($("&lt;strong id='bu'&gt;"+ numOfUsers + "&lt;/strong&gt;"));
            }




            setTimeout(getuserlist(),1);

        },
    });

}
</code></pre>

<p>And finally, the initializer of it in index.html:</p>

<p>----something</p>

<pre><code>       &lt;script type="text/javascript"&gt;

                var chat = new Chat(&lt;?php echo $room;?&gt;);
                chat.getuserlist();

            &lt;/script&gt;
                      &lt;strong id="bu"&gt;
                        &lt;?php
                        echo $numOfUsers;
                        ?&gt;
                        &lt;/strong&gt;
</code></pre>

<p>------something</p>

<p>In here, i want to check database situation(rows of the certain room), and change the number of chatters in that room simultaneously. 'current' is for number of users and 'room' is for the name of the room.But there is no change even though the num of rows of database is changing. Which part i am missing?
Note: I have added online.js in index.php</p>
