First this is related question of PHP: Online Offline Status But as my approch is little different and issue too so I thought new question would be better.
Now I ha
Without knowing your DB structur it's kind of a guess.
if ($time >= $loggedtime)
You are comparing a string like '2012-11-01 10:10:10' with whatever $time is in your DB. This seems to be the problem here.
You could/should use UNIX timestamps. They can be compared easily.
If $time were a UNIX timestamp you could just do:
if ($time >= time()-300)
EDIT:
Change your query to get a UNIX timestamp for online
$query = 'SELECT userid, handle, UNIX_TIMESTAMP(online) as online FROM ^users ORDER BY userid ASC';
EDIT2: To make it more clear: In your first version you were comparing two Dates in the form '2012-11-01 10:10:10'
if ('2012-11-01 10:10:10' < '2012-11-02 10:10:10')
This can't work in PHP - it's like doing:
if ('apples' < 'bananas')
You have to compare numbers. Therefore i suggested using unix timestamps which can be easily compared.