Frank, it's a mind-boggling problem but once you think about the solution it's very simple. Set up a timestamp field in each user's record named 'lastaction', and simply compare it to the current time. If it's, say within the last X minutes, then that user should appear as logged on. Cycle through all the user records, to grab all of them online.
$result = mysql($db, "SELECT UNIX_TIMESTAMP(lastaction) FROM $member_table"); // must convert the lastaction to unix timestamp
$totalonline = 0;
while ($users = mysql_fetch_row($result))
{
$online = $others[0]; // read the only queried field, lastvisit
if (($online + 1200 > time())) { $totalonline++; } // if the last action + 1200 seconds is greater than the current time, add one to $totalonline
}