Alternating Graphic - Every Week

2 posts by 2 authors in: Forums > CMS Builder
Last Post: July 30, 2012   (RSS)

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:

$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/