SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Thread: SQL Query

Hybrid View

  1. #1
    Free me php klassicd's Avatar
    Join Date
    Sep 2001
    Location
    San Diego
    Posts
    509
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    SQL Query

    A little help please. I have a timestamp(14) column. I would like to select all the rows that are 5 mins old from the database using the timestamp column. Could someone help me with the query for this. Is there one? Or would i have to select everything and do it through php? Is there an easier way?

  2. #2
    SitePoint Enthusiast
    Join Date
    Aug 2001
    Location
    Los Angeles
    Posts
    51
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Haven't really tested this, but worth a try

    $result = mysql_query("select max(timestamp) from yourtable", $dblink);
    list($maxstamp) = mysql_fetch_row($result);

    $q = "select * from yourtable where $maxstamp-timestamp<50000";
    $recent_5min_result = mysql_query($q,$dblink);
    Do you have a career or job related web site?
    Earn 5 cents per click by joining our affiliate program.
    Click Here

  3. #3
    Free me php klassicd's Avatar
    Join Date
    Sep 2001
    Location
    San Diego
    Posts
    509
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    What exactly

    What exactly are you doing? Selecting the highest stamp and seeeing if its less than 5 mins old?

    Isnt there something like..

    DELETE FROM chat_users WHERE (CURTIME - column) > 3000;

    WHERE 3000 = 5 mins and column is the timestamp(14) column.

  4. #4
    Making a better wheel silver trophy DR_LaRRY_PEpPeR's Avatar
    Join Date
    Jul 2001
    Location
    Missouri
    Posts
    3,428
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    try

    Code:
    DELETE FROM chat_users WHERE column < NOW() - INTERVAL 5 MINUTE
    http://www.mysql.com/doc/D/a/Date_an...functions.html
    - Matt ** Ignore old signature for now... **
    Dr.BB - Highly optimized to be 2-3x faster than the "Big 3."
    "Do not enclose numeric values in quotes -- that is very non-standard and will only work on MySQL." - MattR


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
  •