0

Hey Guys,

I know there has to be a way to automatically delete a row in a MySQL table on a specified date. I am just brain dead today :icon_confused:

Let's just say I have CMS that I input posts and want one of the fields in the table to be "delete_date" and if I put a date in that field it would delete that row on the date specified. If I do not enter a date it would not auto delete.

What would be the best way to do this using PHP/MySQL. Tips or examples would help, maybe even tutorial links.

Any help will be greatly appreciated :)

Thanks,

Drew

3
Contributors
5
Replies
8
Views
6 Years
Discussion Span
Last Post by drewpark88
1

One solution could be to create a trigger but I am not sure that it is what it is needed in your case. As I understood you want to predefine the date that the row will be deleted and not be deleted until that day. So the other way is to create a cron job that will run every day (the first second of each day) and make a simple delete based on the date you specified.

0

I have several new posts about promotions that are date sensitive. So many different events, orientations, etc that I need a way to automate the removal of these items sitewide.

Thanks

Whats the reasoning behind hard deleting the row in the first place?

1

Instead of hard deleting them would it not be easier and more effective to just limit the display of them by the "delete_date" parameter?

So when displaying posts only display posts where delete_date < NOW()?

Then you have no time priority to physically remove the items from your database and could have a database "clean-up" routine that can be run manually whenever you are logged in, or maybe runs anytime a new post is made so you don't need a cron script etc to do it?

Votes + Comments
Awesome!
0

Thanks for the response, I believe you are right on the money. That seems to be the best way to execute this :)

Instead of hard deleting them would it not be easier and more effective to just limit the display of them by the "delete_date" parameter?

So when displaying posts only display posts where delete_date < NOW()?

Then you have no time priority to physically remove the items from your database and could have a database "clean-up" routine that can be run manually whenever you are logged in, or maybe runs anytime a new post is made so you don't need a cron script etc to do it?

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.