Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Dec 2003
    Location
    texas
    Posts
    96
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Delete a db entry after a certain amount of time.

    Hello,
    I was wondering if you could tell me if this is possible? Can PHP delete an item that is in a db after 7 days or 168 hours?

    I am going to be inserting items into a database through a form, and was wanting an item to be deleted after 168 hours. Therefore I can't go and manually adjust my time each time sometime is inserted into a database. Can you let me know where I should start?

    I am off to look at google, but I wanted to start here.
    thanks
    bri

  • #2
    Senior Coder
    Join Date
    Apr 2007
    Location
    Quakertown PA USA
    Posts
    1,028
    Thanks
    1
    Thanked 125 Times in 123 Posts
    Using a Cron Job, you can run a script which deletes the record.

  • #3
    Regular Coder
    Join Date
    Sep 2006
    Location
    Vermont, USA
    Posts
    154
    Thanks
    0
    Thanked 6 Times in 6 Posts
    If you're not familiar with cron, run a single query every time a page is loaded (or form submitted).

    Code:
    DELETE FROM table WHERE DATEDIFF(NOW(), created_date) > 7
    Active PHP/MySQL application developer available for immediate work.
    syosoft.com mavieo.com - Remote Web Site Administration Suite - Reseller Ready


  •  

    Posting Permissions

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