Reputation: 2000
I have a simple website where users can post ads, i want to set an expiry date based in a mysql table when the user uploads an ad, say in one months time and then when that date is reached then my delete script will be automatically run to remove the ad
any help much appreciated!!
Upvotes: 0
Views: 3070
Reputation: 5239
add query:
INSERT INTO ads (expires_on, ...)
VALUES (now() + INTERVAL 1 MONTH, ...)
delete query:
DELETE from ads
WHERE expires_on <= now()
And run them in cron jobs, as others mentioned.
Upvotes: 0
Reputation: 15374
Better yet, if the data set is small, ignore the expired ads in your main code instead of deleting them at all.
Upvotes: 2
Reputation: 360632
add script:
INSERT INTO ads (expires_on, ...)
VALUES (now() + INTERVAL 1 MONTH, ...)
delete script:
SELECT ...
WHERE expires_on <= now()
Simply have your delete script run once a day (e.g. cron job)
Upvotes: 3