tags:

views:

35

answers:

3

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]

A: 

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.

Kamil Szot
+2  A: 

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.

Galen
+1  A: 

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.

BillThor
I don't get this, there's actually a function within the database that does that?
Crays
Mysql has an adddate function that you can use to add intervals of various types. Use the appropriate interval when adding a theme. I believe you may be able to use it to default the theme to theme of the week. I notices a type in the select note. It should read 'expires < now()'.
BillThor