could add a column your user database to keep track of if an individual user is logged in then just query it and return the number of rows affected:\
mysql_query("SELECT uid FROM user_table WHERE loggedin='1';");
$numloggedin = mysql_affected_rows();
mysql_affected_rows() gets the number of rows the last mysql_query affected (whether it by SELECT UPDATE any other MySQL query)
You could also go further and add a script on each page that keeps track of each user's activity to combat someone closing their browser without logging out.
mysql_query("UPDATE user_table SET lastactivity = '".time()."' WHERE userid='".$userid."';");
then then you could adjust how long since you want your user's last action to consider them non active
mysql_query("SELECT uid FROM user_table WHERE loggedin='1' AND lastactivity > '".time()-3600."';");
$numloggedin = mysql_affected_rows();
time() returns number of seconds since the unix epoch (Jan 1st 1970) so you'd just time() - 3600 to get all activity within the last hour
PS: none of that sql is tested so there may be some errors but you should get the general direction.
Edit: time() returns a 10 digit integer so INT(10) would work in a mysql database and i think modern versions of mysql consider bools to be INT(1) so they will return a 1 or 0 to indicate true or false