Results 1 to 4 of 4
  1. #1
    Join Date
    Apr 2009
    Location
    Scotland
    Posts
    177

    Delete Older then 1 Day from DB [MySQL & PHP]

    Hi.

    I want too delete records from a database that are over 1 day old, Id like this too happen when someone requests the page with the code on it (I dont require a cron job (I dont know how too use them))

    This is what Ive tried soo far

    PHP Code:
    $sql 'DELETE FROM table  WHERE `when` < DATE_SUB(CURDATE(), INTERVAL 1 Day)';


    $result mysql_query($sql); 
    but no luck
    Darren Tod
    RPD Hosting

  2. #2
    Join Date
    Feb 2005
    Location
    Australia
    Posts
    5,842
    Looks like it should work. Is your field ("when") a datetime type?
    Chris

    "Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them." - Laurence J. Peter

  3. #3
    Join Date
    Apr 2009
    Location
    Scotland
    Posts
    177
    Hi.

    Ye heres the structure
    Code:
    `when` datetime default NULL,
    Darren Tod
    RPD Hosting

  4. #4
    Join Date
    Apr 2009
    Location
    Scotland
    Posts
    177
    Aplogies, I had the when field named as 'datecode', after I renamed it, it appears too be working, I wont know till tomorrow tho
    Darren Tod
    RPD Hosting

Posting Permissions

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