FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


and if





ChrisCh
Ok I'm also trying to work out how to do an "and if"... Example:

Code:
if($variable1 == 1) AND IF($variable2 == 2){
       print 'Example';
}


I tried
Code:
if($variable1 == 1) if($variable2 == 2){
       print 'Example';
}

but it did it if only one of the if statements were correct (ie. if $variable1 equalled 1 but $variable2 equaled 20). Does anyone know how to change this to make sure both if statements are true before printing Example? Smile
The Conspirator
Code:
if($variable1 == 1 and $variable2 == 2){
       print 'Example';
}
hexkid
ChrisCh wrote:
Ok I'm also trying to work out how to do an "and if"... Example:

Code:
if($variable1 == 1) AND IF($variable2 == 2){
       print 'Example';
}

This is a syntax error.

ChrisCh wrote:
I tried
Code:
if($variable1 == 1) if($variable2 == 2){
       print 'Example';
}

This is ok. It is equivalent to
Code:
if ($variable1 == 1) {
  if ($variable2 == 2) {
    print 'Example';
  }
}


ChrisCh wrote:
but it did it if only one of the if statements were correct (ie. if $variable1 equalled 1 but $variable2 equaled 20).
Hmmmm ???? I don't get the same behaviour!
ChrisCh
Thanks to The Conspirator for answering my question! Hexkid, i think you thought I meant something else by my question! Not sure what tho... anyway thanks to you both for your help Smile

You can lock this if you want - my question has been answered Smile
Antoine_935
The Conspirator wrote:
Code:
if($variable1 == 1 and $variable2 == 2){
       print 'Example';
}

"and" is not often used in programming languages. prefer "&&"
Related topics
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.