elmas156 Posted August 27, 2008 Share Posted August 27, 2008 Hello everyone, Here's what I'm trying to do: I want to have an if/else statement to say "if one thing true AND another thing is true then do something" I'm sure there's a simple solution but I don't know what it is... can anyone help please? Here's what I've got but it's not working: <?php if ($r1 > 0) AND ($r2 < 1) { echo "There is no information for widget 2."; } else { echo "There is info on widget 2."; } ?> Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted August 27, 2008 Share Posted August 27, 2008 That should work, although you should use "&&", not "AND". What are the results? How do you know it doesn't work? Change <?php if ($r1 > 0) AND ($r2 < 1) { ?> to <?php if ($r1 > 0 && $r2 < 1) { ?> Ken Quote Link to comment Share on other sites More sharing options...
coder_ Posted August 27, 2008 Share Posted August 27, 2008 you forgot opening and closing braces in if statement: <?php if ( ($r1 > 0) && ($r2 < 1) ) { echo "There is no information for widget 2."; } else { echo "There is info on widget 2."; } ?> This is how it should be. EDIT: Ken was faster...hehe Quote Link to comment Share on other sites More sharing options...
True`Logic Posted August 27, 2008 Share Posted August 27, 2008 sometimes it's better to seperate each set of clauses though, <? if (($r1 > 0)&&($r2<1)) { /* */ } ?> Quote Link to comment Share on other sites More sharing options...
elmas156 Posted August 27, 2008 Author Share Posted August 27, 2008 Thank you very much gentlemen (or ladies ;-) it works perfectly now. One more question... could you use this same method with more than 2... maybe 4 or 5 clauses? Like this: <?php if (($a < 1) && ($b > 0) && ($c > 0) && ($d > 0) && ($e > 0)) { echo "Do this."; } else { echo "Do that."; } ?> Quote Link to comment Share on other sites More sharing options...
coder_ Posted August 27, 2008 Share Posted August 27, 2008 As many as you want. Quote Link to comment Share on other sites More sharing options...
elmas156 Posted August 27, 2008 Author Share Posted August 27, 2008 Thanks everyone, yet again, for your help. I've never come across so many people willing to share their knowledge and help others out as I have here on this forum. You guys are great! Quote Link to comment Share on other sites More sharing options...
coder_ Posted August 27, 2008 Share Posted August 27, 2008 Thanks everyone, yet again, for your help. I've never come across so many people willing to share their knowledge and help others out as I have here on this forum. You guys are great! Believe me, neither do I. I am from Croatia, and PHP scene sucks so i have to find help here if i need one. 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.