Jump to content

Auto Delete After Certain Date


e1seix

Recommended Posts

Hi all,

 

Have a bit of a question. Was wondering does anyone have any hints or links to code that would set up an SQL table where after a specified date the record would automatically delete itself. The reason why I ask is that I have an affiliate site (so shoot me! lol) and I can offer certain discount codes for limited times only and rather than have to keep on manually deleting the codes when they expire, at the time of inserting a table entry I could enter an expiry date, it would make life so much easier.

 

What kind of table rows would I need etc and - can it be done full stop?

 

Any tips?

 

Cheers,  ;D

Link to comment
https://forums.phpfreaks.com/topic/108013-auto-delete-after-certain-date/
Share on other sites

i'm not a big fan of deleting stuff. unless the table is going to get HUGE, which it sounds like it will not, just have a column for an expiration date, and in your php when you select the current codes, filter out the expired ones with a where clause. this way you will always have the old ones for reference/auditing/etc.

 

if you feel you HAVE to delete them, still use the expiration, and create a php script that runs a

DELETE FROM tablename WHERE expiration_date < NOW()

then run the script with a cronjob every night

 

...but again...i wouldn't delete them, just filter

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.