SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    Keep it simple, stupid! bokehman's Avatar
    Join Date
    Jul 2005
    Posts
    1,935
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    I suck at optimising my MySQL queries

    Would it be possible to omit or somehow join these queries into one optimised query???
    PHP Code:
    function online_users()
    {
        
    $query "DELETE FROM `online_users` WHERE `ip` = '".$_SERVER['REMOTE_ADDR']."' OR `updated` < '".(time() - 1800)."'";
        
    $result mysql_query($query) or die ($query.' -- '.mysql_error());
        
    $query "INSERT INTO `online_users` (`ip`, `updated`) VALUES ('".$_SERVER['REMOTE_ADDR']."', '".time()."')";
        
    mysql_query($query) or die ($query.' -- '.mysql_error());
        
    $query "SELECT * FROM `online_users`";
        
    $result mysql_query($query) or die ($query.' -- '.mysql_error());
        return 
    mysql_num_rows($result);


  2. #2
    SitePoint Wizard Ren's Avatar
    Join Date
    Aug 2003
    Location
    UK
    Posts
    1,060
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I cant see of a better way todo this, the delete statement deletes the current user and all other users that are 1800s old, so cant combine it with the update.

  3. #3
    Keep it simple, stupid! bokehman's Avatar
    Join Date
    Jul 2005
    Posts
    1,935
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok. Anyway thanks for having a look.


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
  •