Page 1 of 1

24-Hour Switch

Posted: Mon Apr 12, 2004 6:27 pm
by SilverMist
Is it possible to make a code that, after twenty four hours, switches a quote. Like a new quote would appear every 24 hours... If this is possible, does anyone have any ideas on how it would be coded?

Posted: Mon Apr 12, 2004 6:31 pm
by d3ad1ysp0rk
Cron


before i give you an example of what to do, is it a random quote, or a linear one? (day1 = quote1, day2 = quote2, etc)

Posted: Mon Apr 12, 2004 6:35 pm
by SilverMist
Random :D

Posted: Mon Apr 12, 2004 6:39 pm
by andre_c
If it's for a web page, you don't need cron. You can just check to see if the date has changed every time someone loads the page. It would require saving the last date on a db or a file.

I suppose you could use cron (not the way I would do it though)

Posted: Mon Apr 12, 2004 6:49 pm
by SilverMist
I'm still not sure how to code it. Any examples, snippets, or suggestions would be great! :mrgreen:

Posted: Mon Apr 12, 2004 6:51 pm
by andre_c
do you have a db?

Posted: Mon Apr 12, 2004 6:53 pm
by SilverMist
Yes.

Posted: Mon Apr 12, 2004 7:09 pm
by andre_c
then every time someone loads the page, save the date to a field on the db. But before that, check if the the current date matches the one on the database.

Code: Select all

<?
$last_day_q = mysql_query('SELECT last_day FROM some_table');
$last_day = mysql_result($last_day_q, 0);

if (date("d")==$last_day) {
  // do this
} else {
  // do that
}

$today = date("Y-m-d");
$save_day = mysql_query("INSERT INTO some_table (last_day) VALUES( '$today");
... or something like that