SitePoint Sponsor

User Tag List

Results 1 to 6 of 6

Thread: SQL problem :(

  1. #1
    SitePoint Wizard xyuri's Avatar
    Join Date
    Jul 2002
    Location
    Brisbane
    Posts
    1,487
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    SQL problem :(

    Iwant to find the numer of people who have accessed my site in the last five minutes. (but i abviously having difficulties). at the moment i have been trying and experimenting with the following code:
    PHP Code:
    $on_online =  mysql_query("SELECT count(*) FROM activity WHERE lactive>('$date $time'-'0000-00-00 00:00:05')"); 
    but doesnt to anything for me.

    how can it be done ? (preferable through SQL and not too much PHP).

  2. #2
    SitePoint Wizard Mincer's Avatar
    Join Date
    Mar 2001
    Location
    London | UK
    Posts
    1,140
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm presuming lactive is a DATETIME column with the last active time??

    PHP Code:
    $sql =  "SELECT COUNT(*) FROM activity" ;
    $sql .= " WHERE UNIX_TIMESTAMP( NOW() ) - UNIX_TIMESTAMP( lactive ) <= 300" 
    Matt.

  3. #3
    SitePoint Wizard xyuri's Avatar
    Join Date
    Jul 2002
    Location
    Brisbane
    Posts
    1,487
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yes, it is a datetime column. but that codxce didnt work is there maybe a mysql functions or something, maybe a tutorial that you could point me to that i might be able to learn from ? (i dont generaly use C&P'd code)

    I'm using the following code now:
    PHP Code:
                        $sql =  "SELECT COUNT(*) FROM activity";
                        
    $sql .= " WHERE UNIX_TIMESTAMP( NOW() ) - UNIX_TIMESTAMP( lactive ) <= 300";
                        
                        
    $on_online =  mysql_query($sql);
                        ECHO 
    mysql_result($no_online0"count(*)");
                        
    //$c_user->no_of_reg_users(); 

  4. #4
    SitePoint Wizard Mincer's Avatar
    Join Date
    Mar 2001
    Location
    London | UK
    Posts
    1,140
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You have a couple of errors, I think your code should be:

    PHP Code:
    $sql =  "SELECT COUNT(*) FROM activity";
    $sql .= " WHERE UNIX_TIMESTAMP( NOW() ) - UNIX_TIMESTAMP( lactive ) <= 300";
                        
    $no_online =  mysql_query($sql); // did say '$on_online'
    ECHO mysql_result($no_online0); // simplified, not sure if your method would work or not 
    Matt.

  5. #5
    SitePoint Wizard xyuri's Avatar
    Join Date
    Jul 2002
    Location
    Brisbane
    Posts
    1,487
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    YAY ! it works. thanx matt

  6. #6
    SitePoint Wizard Mincer's Avatar
    Join Date
    Mar 2001
    Location
    London | UK
    Posts
    1,140
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by xyuri
    YAY ! it works. thanx matt
    Of course it does!


Bookmarks

Posting Permissions

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