PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
gangboy
Forum Newbie
Posts: 14 Joined: Tue Jan 06, 2004 11:58 am
Location: Constanţa, România
Post
by gangboy » Thu Mar 11, 2004 11:35 am
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
TheBentinel.com
Forum Contributor
Posts: 282 Joined: Wed Mar 10, 2004 1:52 pm
Location: Columbus, Ohio
Post
by TheBentinel.com » Thu Mar 11, 2004 11:39 am
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.
Illusionist
Forum Regular
Posts: 903 Joined: Mon Jan 12, 2004 9:32 pm
Post
by Illusionist » Thu Mar 11, 2004 11:40 am
i would get rid of the brackets and the else's
gangboy
Forum Newbie
Posts: 14 Joined: Tue Jan 06, 2004 11:58 am
Location: Constanţa, România
Post
by gangboy » Thu Mar 11, 2004 11:44 am
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.
xisle
Forum Contributor
Posts: 249 Joined: Wed Jun 25, 2003 1:53 pm
Post
by xisle » Thu Mar 11, 2004 11:46 am
you are stuck on Spring because of this:
$month > 2
andre_c
Forum Contributor
Posts: 412 Joined: Sun Feb 29, 2004 6:49 pm
Location: Salt Lake City, Utah
Post
by andre_c » Thu Mar 11, 2004 11:46 am
You need to change the || for a &&. All of your statements come out to be TRUE if you use ||
Last edited by
andre_c on Thu Mar 11, 2004 11:48 am, edited 1 time in total.
Illusionist
Forum Regular
Posts: 903 Joined: Mon Jan 12, 2004 9:32 pm
Post
by Illusionist » Thu Mar 11, 2004 11:47 am
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.
TheBentinel.com
Forum Contributor
Posts: 282 Joined: Wed Mar 10, 2004 1:52 pm
Location: Columbus, Ohio
Post
by TheBentinel.com » Thu Mar 11, 2004 11:50 am
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?
gangboy
Forum Newbie
Posts: 14 Joined: Tue Jan 06, 2004 11:58 am
Location: Constanţa, România
Post
by gangboy » Thu Mar 11, 2004 11:53 am
TheBentinel.com wrote: Would that do it?
YES! That did it!
Thank you all!