Results 1 to 5 of 5

Thread: Select Online User

  1. #1

    Thread Starter
    Hyperactive Member naruponk's Avatar
    Join Date
    Feb 2004
    Location
    Some where in the world
    Posts
    423

    Select Online User

    Hi there

    How can i use SQL syntax to select a user who have lastvisit time within last 5 minutes?

    I have try like this but failed
    Code:
    $result = mysql_query("Select * from tblmember WHERE " .( time() - 300 ) . " <= lastvisit;");
    
    also
    
    WHERE DATE_SUB(CURDATE(),INTERVAL -5 Minute) <= lastvisit
    does anyone have an experience with something like this?
    how can i do that

    Thanks for advance

  2. #2
    <?="Moderator"?> john tindell's Avatar
    Join Date
    Jan 2002
    Location
    Brighton, UK
    Posts
    1,099

    Re: Select Online User

    Hey, what is delete all the users who have been not be active within the last five minutes, or the current user

    PHP Code:
    $query "DELETE FROM _ONLINE_USERS WHERE session_id = '"session_id() . "' OR DATE_SUB(now(), interval 5 minute) >= time"
    Then i insert the current users information in to my _ONLINE_USERS table using
    PHP Code:
    $query "INSERT INTO 
                                    
    {$this->dbc->prefix}_ONLINE_USERS 
                                    (username,ip_address,session_id,time,page,user_agent)
                                VALUES
                                    (
                                        '
    $uname',
                                        '
    {$_SERVER['REMOTE_ADDR']}',
                                        '" 
    session_id(). "',
                                        NOW(),
                                        '
    {$_SERVER['PHP_SELF']}?{$_SERVER['QUERY_STRING']}',
                                        '
    {$_SERVER['HTTP_USER_AGENT']}'
                                    )"


  3. #3

    Thread Starter
    Hyperactive Member naruponk's Avatar
    Join Date
    Feb 2004
    Location
    Some where in the world
    Posts
    423

    Re: Select Online User

    Is this a code that can use to select active user?

    DATE_SUB(now(), interval 5 minute) >= time

    I already have a column that use to keep user's lastvisit
    can i just select by that column?

    Thanks

  4. #4
    <?="Moderator"?> john tindell's Avatar
    Join Date
    Jan 2002
    Location
    Brighton, UK
    Posts
    1,099

    Re: Select Online User

    Quote Originally Posted by naruponk
    DATE_SUB(now(), interval 5 minute) >= time
    That selects the users within the lat five minutes.

  5. #5

    Thread Starter
    Hyperactive Member naruponk's Avatar
    Join Date
    Feb 2004
    Location
    Some where in the world
    Posts
    423

    Re: Select Online User

    Thanks man

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width