kdewitt Posted March 10, 2006 Share Posted March 10, 2006 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 Quote Link to comment Share on other sites More sharing options...
joecooper Posted March 11, 2006 Share Posted March 11, 2006 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 returningand before the script, add$GLOBAL_MONTH = '9';THIS IS TO TEST IT, run the script and it should return: The current season is: Fallthen change the number 9 to 1, and it should return: The current season is: Springthen change the number to 5, and it should return: The current season is: Summerand 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] Quote Link to comment Share on other sites More sharing options...
Barand Posted March 11, 2006 Share Posted March 11, 2006 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 : Spring2 : Spring3 : Spring4 : Spring5 : Spring6 : Summer7 : Summer8 : Summer9 : Fall10 : Fall11 : Fall12 : FallThe 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.