Jump to content


Photo

defining a seasonal period


  • Please log in to reply
2 replies to this topic

#1 kdewitt

kdewitt
  • New Members
  • Pip
  • Newbie
  • 1 posts

Posted 10 March 2006 - 04:41 PM

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

#2 joecooper

joecooper
  • Members
  • PipPipPip
  • Advanced Member
  • 358 posts

Posted 11 March 2006 - 12:04 AM

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,

$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";

Signature:
[/a]
[a href="http://www.planet-so...=1999&lngWId=8" target="_blank"]EzLogin 1.0[/a]
[a href="http://www.essexracers.com" target="_blank"]Essexracers.com[/a]
Msn Messenger: joe@joeyjoe.co.uk

#3 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,021 posts

Posted 11 March 2006 - 10:20 AM

Kate,

A quick test of your code shows it to be OK

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>";
}

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

if ($season == 'Spring') {

         //  process spring stuff

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

         //  process fall stuff

}

so nothing happens in Summer.

If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users