Avatar of test1234
test1234Flag for United States of America asked on

Delete 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 was told through a cron job, I don't know what that is....but is there a way to do this through a php script?
PHP

Avatar of undefined
Last Comment
test1234

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
BrianGEFF719

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Khanh Doan

You should have field like 'addtime' and its value is timestamp when you insert it.
then. put a query in top of page that will delete entry is older than 7days
like this:


$query = "DELETE * FROM table WHERE addtime >= " . time() - 604800 .";

something like that.
ASKER
test1234

Okay thanks...I think I can figure it out from there.  Thanks for the quick response
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck