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!!
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 (eg cron job)
Better yet, if the data set is small, ignore the expired ads in your main code instead of deleting them at all.
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.