Page 1 of 1
Logo by season
Posted: Thu Mar 11, 2004 11:35 am
by gangboy
What's wrong in this code?
Code: Select all
<?php
$month = date("n");
if($month < 3 || $month > 11) { print "suslogo_winter.jpg"; } else
if($month < 6 || $month > 2) { print "suslogo_spring.jpg"; } else
if($month < 9 || $month > 5) { print "suslogo_summer.jpg"; } else
if($month < 12 || $month > { print "suslogo_autumn.jpg"; }
?>
Thanks
Re: Logo by season
Posted: Thu Mar 11, 2004 11:39 am
by TheBentinel.com
gangboy wrote:What's wrong in this code?
Nothing strikes me right off. It looks like your second condition should be true and you should get the spring image.
What are you actually getting back? Knowing that will help nail it down.
Posted: Thu Mar 11, 2004 11:40 am
by Illusionist
i would get rid of the brackets and the else's
Re: Logo by season
Posted: Thu Mar 11, 2004 11:44 am
by gangboy
TheBentinel.com wrote:What are you actually getting back? Knowing that will help nail it down.
I get only spring and winter images.
TheBentinel.com wrote:i would get rid of the brackets and the else's
That will return all the images.
Posted: Thu Mar 11, 2004 11:46 am
by xisle
you are stuck on Spring because of this:
$month > 2
Posted: Thu Mar 11, 2004 11:46 am
by andre_c
You need to change the || for a &&. All of your statements come out to be TRUE if you use ||
Posted: Thu Mar 11, 2004 11:47 am
by Illusionist
if you do as andre_c said, and change the ors to ands and get rid of the brackets and else's no you wont get back every image.
Posted: Thu Mar 11, 2004 11:50 am
by TheBentinel.com
xisle wrote:you are stuck on Spring because of this:
$month > 2
Yep, that's it. But you could get around it by subtracting one from the month and getting rid of the or's
Code: Select all
<?php
$month = date("n") - 1;
if($month < 3) { print "suslogo_winter.jpg"; } else
if($month < 6) { print "suslogo_spring.jpg"; } else
if($month < 9) { print "suslogo_summer.jpg"; } else
{ print "suslogo_autumn.jpg"; }
?>
Would that do it?
Posted: Thu Mar 11, 2004 11:53 am
by gangboy
TheBentinel.com wrote:Would that do it?
YES! That did it!
Thank you all!