User online offline status - offline status issue

前端 未结 2 714
梦毁少年i
梦毁少年i 2021-01-16 05:01

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

2条回答
  •  心在旅途
    2021-01-16 05:57

    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.

提交回复
热议问题