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."; } ?> Link to comment https://forums.phpfreaks.com/topic/121511-multiple-fields-on-ifelse-statements/ 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 Link to comment https://forums.phpfreaks.com/topic/121511-multiple-fields-on-ifelse-statements/#findComment-626628 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 Link to comment https://forums.phpfreaks.com/topic/121511-multiple-fields-on-ifelse-statements/#findComment-626631 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)) { /* */ } ?> Link to comment https://forums.phpfreaks.com/topic/121511-multiple-fields-on-ifelse-statements/#findComment-626632 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."; } ?> Link to comment https://forums.phpfreaks.com/topic/121511-multiple-fields-on-ifelse-statements/#findComment-626640 Share on other sites More sharing options...
coder_ Posted August 27, 2008 Share Posted August 27, 2008 As many as you want. Link to comment https://forums.phpfreaks.com/topic/121511-multiple-fields-on-ifelse-statements/#findComment-626646 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! Link to comment https://forums.phpfreaks.com/topic/121511-multiple-fields-on-ifelse-statements/#findComment-626648 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. Link to comment https://forums.phpfreaks.com/topic/121511-multiple-fields-on-ifelse-statements/#findComment-626651 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.