View Full Version : If the time now is a new hour then...

11-07-2007, 04:35 PM

Im trying to think of a way to write a piece of code that basiaclly does this.

If the time now is a new hour then...
If the time now is a new day then...
if the time is a new week then...
if the time now is a new month then...

once I have that I can create mysql tables at the right time to store data.

Thanks in advance!

11-07-2007, 06:42 PM

11-08-2007, 01:13 AM
you could use a cookie. I'm still learning php so I can't code this with out referring to a manual. But...

create an array with hour, day, week, month ($now)

if cookie exists then read data into array $then, else create cookie with $now

then test the arrays against each other

11-08-2007, 01:22 AM
if ($now['hour'] = ($then['hour'] + foo))
do hour thing

where foo is the int of one hour or whatever time

11-08-2007, 05:08 AM
It depends on how you want the content changed. If you want something to execute for each user as the hour/whatever changes use a cookie. If you want all users to affect it then you just need to store the time in a file(preferably) or database, and compare it when the page loads. file_put_contents() (http://php.net/file_put_contents) file_get_contents() (http://php.net/file_get_contents) time() (http://php.net/time)