Page 3 of 3
Posted: Wed Jul 25, 2007 3:55 pm
by Zoxive
outdoorxtreme1 wrote:
then I get an echo but the pictures appear randomly each time the page is refreshed.
Uhhh, isn't that what you want it to do? / Told us you wanted it to do?
Your posts title its "Need help with random image code"
So yea...
Posted: Thu Jul 26, 2007 7:20 am
by outdoorxtreme1
In my very first post I asked if someone please tell me what I need to change or add to allow this script to display a new image weekly instead of every time the page is refreshed.
Posted: Thu Jul 26, 2007 9:20 am
by superdezign
outdoorxtreme1 wrote:In my very first post I asked if someone please tell me what I need to change or add to allow this script to display a new image weekly instead of every time the page is refreshed.
What??? Then why on earth have you been using ORDER BY RAND()?
You're going to need to set up your script to store in the database what the current image to display is, and update it weekly.
Code: Select all
if(date('N') == 7) // If today is sunday
{
mysql_query("INSERT INTO `imageTable` SET `weekOf` = '" . date('Y-m-d') . "', `image` = (SELECT `image` FROM `links` ORDER BY RAND() LIMIT 1);");
}
// Display
$result = mysql_query("SELECT `image` FROM `imageTable` ORDER BY `weekOf` DESC LIMIT 1;");
$result = mysql_fetch_object($result);
echo '<img src="' . $result->image . '" />';
That code assumes that your page is visited at least daily, however. You'll need to come up with the logic to have it look at previous entries and their dates in order to determine whether or not it should be updated.