Jump to content

Multiple fields on if/else statements


elmas156

Recommended Posts

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

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

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.";

}
?>

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.