Crays
Crays

Reputation: 2508

Auto update after specific day passed

Hey guys, i've this theme of the week script, easy, just post like normally, save in database and echo it in a column.

But since its theme of the week, i would like it to automatically renew the value to say "none" or "not set" after a week. I know cron jobs could do this but is there another way? [Running in PHP]

Upvotes: 1

Views: 184

Answers (3)

BillThor
BillThor

Reputation: 7576

Add an expires column to the database and set it to now + 7days. Default it to a date way in the future 9999-12-31 for Mysql. Then select based on the expiry being > now.

As a side benifit you can easily implement theme of the day, month, season, year... etc.

Upvotes: 1

Galen
Galen

Reputation: 30170

Cron job would be the optimal solution but if you can't do that you could have your main page check if it's time to "renew" on every page load. It's a lot less efficient but it's an alternative if you don't have access to cron jobs.

Upvotes: 2

Kamil Szot
Kamil Szot

Reputation: 17817

You could keep it in the database along with the date of saving and determine if it expired by comparing that date plus one week with current date.

Upvotes: 0

Related Questions