Another possible way is to make a field in the table called active. Set the this fields default value to 0 then when someone logs in, it will update that field to increment by 1.
$sql = mysql("SELECT active from table");
$result = mysql_fetch_array($sql);
$number = $result['number'];
//if login is successful
$new = $number++
$update = mysql("UPDATE table SET(number) VALUES('$new')");
If you have someone log off just do the oposite.
Then where ever you want to display the number of users online then just do another query on that page and echo out the number. This sounds confusing but it really isn't.
Let me know what you think,