Alternating Graphic - Every Week
2 posts by 2 authors in: Forums > CMS Builder
Last Post: July 30, 2012 (RSS)
By Perchpole - July 26, 2012
Hello, All -
I want to put a small widget on a site which shows an alternating graphic every week. In week one the graphic would be blue. In week two it would be red. In week three it would be back to blue again, and so on...
The graphic needs to change over every Thursday.
I'm sure the code for this is supremely simple but I just can't crack it.
Any help would be much appreciated.
:0)
Perch
I want to put a small widget on a site which shows an alternating graphic every week. In week one the graphic would be blue. In week two it would be red. In week three it would be back to blue again, and so on...
The graphic needs to change over every Thursday.
I'm sure the code for this is supremely simple but I just can't crack it.
Any help would be much appreciated.
:0)
Perch
Re: [Perchpole] Alternating Graphic - Every Week
By Jason - July 30, 2012
Hi Perch,
One approach you could take would be to create a single record section called "alternating_graphic". In this section, you'll need a text field called "graphic color" This field will always have a value of either blue or red. This record would get updated every thursday, using the following code:
EXAMPLE:
At the end of this code, the value of $alternatingGraphic['graphic_color'] will let you know if you should use the red or blue graphic.
The one catch with this code, is that it assumes the page will be viewed at least once per day. If on a given thursday, the page is never run, the graphic wont get updated until the following week.
Hope this helps get you started
One approach you could take would be to create a single record section called "alternating_graphic". In this section, you'll need a text field called "graphic color" This field will always have a value of either blue or red. This record would get updated every thursday, using the following code:
EXAMPLE:
$dayOfTheWeek = date("l");
$alternatingGraphic = mysql_get("alternating_graphic", 1);
if ($dayOfTheWeek == 4) { // thursday
$today = date("Y-m-d");
$lastUpdated = date("Y-m-d", strtotime($alternatingGraphic['updatedDate']));
if ($today != $lastUpdated) { //change graphic!
$columnsToValues = array();
$columnsToValues['updatedDate='] = 'NOW()';
if ($alternatingGraphic['graphic_color'] == "blue") {
$columnsToValues['graphic_color'] = "red";
}
else {
$columnsToValues['graphic_color'] = "blue";
}
mysql_update("alternating_graphic", 1, null, $columnsToValues);
$alternatingGraphic = mysql_get("alternating_graphic", 1);
}
}
At the end of this code, the value of $alternatingGraphic['graphic_color'] will let you know if you should use the red or blue graphic.
The one catch with this code, is that it assumes the page will be viewed at least once per day. If on a given thursday, the page is never run, the graphic wont get updated until the following week.
Hope this helps get you started
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com
Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/
Jason Sauchuk - Project Manager
interactivetools.com
Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/