24-Hour Switch

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
SilverMist
Forum Commoner
Posts: 65
Joined: Tue Mar 02, 2004 2:06 pm
Location: Canada
Contact:

24-Hour Switch

Post 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?
d3ad1ysp0rk
Forum Donator
Posts: 1661
Joined: Mon Oct 20, 2003 8:31 pm
Location: Maine, USA

Post 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)
User avatar
SilverMist
Forum Commoner
Posts: 65
Joined: Tue Mar 02, 2004 2:06 pm
Location: Canada
Contact:

Post by SilverMist »

Random :D
User avatar
andre_c
Forum Contributor
Posts: 412
Joined: Sun Feb 29, 2004 6:49 pm
Location: Salt Lake City, Utah

Post 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)
User avatar
SilverMist
Forum Commoner
Posts: 65
Joined: Tue Mar 02, 2004 2:06 pm
Location: Canada
Contact:

Post by SilverMist »

I'm still not sure how to code it. Any examples, snippets, or suggestions would be great! :mrgreen:
User avatar
andre_c
Forum Contributor
Posts: 412
Joined: Sun Feb 29, 2004 6:49 pm
Location: Salt Lake City, Utah

Post by andre_c »

do you have a db?
User avatar
SilverMist
Forum Commoner
Posts: 65
Joined: Tue Mar 02, 2004 2:06 pm
Location: Canada
Contact:

Post by SilverMist »

Yes.
User avatar
andre_c
Forum Contributor
Posts: 412
Joined: Sun Feb 29, 2004 6:49 pm
Location: Salt Lake City, Utah

Post 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
Post Reply