Logo by season

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

Post Reply
User avatar
gangboy
Forum Newbie
Posts: 14
Joined: Tue Jan 06, 2004 11:58 am
Location: Constanţa, România

Logo by season

Post by gangboy »

What's wrong in this code? :x

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

Re: Logo by season

Post 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.
Illusionist
Forum Regular
Posts: 903
Joined: Mon Jan 12, 2004 9:32 pm

Post by Illusionist »

i would get rid of the brackets and the else's
User avatar
gangboy
Forum Newbie
Posts: 14
Joined: Tue Jan 06, 2004 11:58 am
Location: Constanţa, România

Re: Logo by season

Post 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.
User avatar
xisle
Forum Contributor
Posts: 249
Joined: Wed Jun 25, 2003 1:53 pm

Post by xisle »

you are stuck on Spring because of this:
$month > 2
User avatar
andre_c
Forum Contributor
Posts: 412
Joined: Sun Feb 29, 2004 6:49 pm
Location: Salt Lake City, Utah

Post by andre_c »

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 »

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 »

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?
User avatar
gangboy
Forum Newbie
Posts: 14
Joined: Tue Jan 06, 2004 11:58 am
Location: Constanţa, România

Post by gangboy »

TheBentinel.com wrote:Would that do it?
YES! That did it!

Thank you all!
Post Reply