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
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

Link to comment
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.