Jump to content
Updating IPB tonight Read more... ×

Archived

This topic is now archived and is closed to further replies.

kdewitt

defining a seasonal period

Recommended Posts

first off, i should point out that i don't really know much at all about php (or html, java script, you name it), but i've been asked to see if i can solve a problem, so here goes:

my company sells books, and we have a website that lists our books by season. we used to have two season, fall and spring, and the website would automatically change to say 'spring books' or 'fall books.' the code that defined that looked, i think, like this:


<?

include_once ('inc/globals.php');

if (($GLOBAL_MONTH >= 7) && ($GLOBAL_MONTH <= 12)) { $season = 'Fall'; }
if (($GLOBAL_MONTH >= 1) && ($GLOBAL_MONTH <= 6)) { $season = 'Spring'; }

?>

and, i think, linked to an external file (globals.php) that looks like this:

<?

list ($GLOBAL_YEAR, $GLOBAL_MONTH, $GLOBAL_DAY) = split("-", date("Y-m-d"));

?>

Here is my question:

We are switching over to a three season year, Spring, Summer, and Fall. I thought that if I just changed the range to

<?

include_once ('inc/globals.php');

if (($GLOBAL_MONTH >= 9) && ($GLOBAL_MONTH <= 12)) { $season = 'Fall'; }
if (($GLOBAL_MONTH >= 1) && ($GLOBAL_MONTH <= 5)) { $season = 'Spring'; }
if (($GLOBAL_MONTH >= 6) && ($GLOBAL_MONTH <= 8)) { $season = 'Summer'; }

?>

that that would create the third season. It doesn't work that way.

Can you help me out?

Thanks,

Kate

Share this post


Link to post
Share on other sites
if (($GLOBAL_MONTH > 8) && ($GLOBAL_MONTH < 13) { $season = "Fall"; }
if (($GLOBAL_MONTH > 0) && ($GLOBAL_MONTH < 6) { $season = "Spring"; }
if (($GLOBAL_MONTH > 5) && ($GLOBAL_MONTH < 9) { $season = "Summer"; }

change it for this, it might make some diffrence.

add:

echo "The current season is: $season";

so you can see what season it is returning

and before the script, add

$GLOBAL_MONTH = '9';


THIS IS TO TEST IT,
run the script and it should return: The current season is: Fall

then change the number 9 to 1, and it should return: The current season is: Spring

then change the number to 5, and it should return: The current season is: Summer


and post what happens.

if you have problems with understanding it,

[code]$GLOBAL_MONTH = '9';
if (($GLOBAL_MONTH > 8) && ($GLOBAL_MONTH < 13) { $season = "Fall"; }
if (($GLOBAL_MONTH > 0) && ($GLOBAL_MONTH < 6) { $season = "Spring"; }
if (($GLOBAL_MONTH > 5) && ($GLOBAL_MONTH < 9) { $season = "Summer"; }
echo "The current season is: $season";[/code]

Share this post


Link to post
Share on other sites
Kate,

A quick test of your code shows it to be OK

[code]for ($GLOBAL_MONTH=1; $GLOBAL_MONTH<=12; $GLOBAL_MONTH++) {

    if (($GLOBAL_MONTH >= 9) && ($GLOBAL_MONTH <= 12)) { $season = 'Fall'; }
    if (($GLOBAL_MONTH >= 1) && ($GLOBAL_MONTH <= 5)) { $season = 'Spring'; }
    if (($GLOBAL_MONTH >= 6) && ($GLOBAL_MONTH <= 8)) { $season = 'Summer'; }

    echo "$GLOBAL_MONTH : $season<br>";
}[/code]

gives, as expected -->

1 : Spring
2 : Spring
3 : Spring
4 : Spring
5 : Spring
6 : Summer
7 : Summer
8 : Summer
9 : Fall
10 : Fall
11 : Fall
12 : Fall

The problem probably lies elsewhere in your script and the new value "Summer" is not being recognised. For example, you may have

[code]if ($season == 'Spring') {

         //  process spring stuff

}
elseif ($season == 'Fall') {

         //  process fall stuff

}[/code]

so nothing happens in Summer.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.