Jump to content

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
Link to comment
https://forums.phpfreaks.com/topic/4616-defining-a-seasonal-period/
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]
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.
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.