funbinod Posted June 8, 2014 Share Posted June 8, 2014 i was trying to apply condition to some query to execute.. if ($col != 'name' or 'item') {// query would execute here} but it is not doing as expected. i want both conditions (or may be more) to execute the query but it is working only in first condition (i.e. $col != 'name') but not working for second (i.e. $col != 'item').. please guide me through Link to comment Share on other sites More sharing options...
Don Jajo Posted June 8, 2014 Share Posted June 8, 2014 Use like this if ($col!=='name' or $col!=='item') {// query would execute here} Once the space, the expression is over "or" is starting a new expression Link to comment Share on other sites More sharing options...
Don E Posted June 8, 2014 Share Posted June 8, 2014 To add to Don Jajo's post, if $col !== 'name' evaluates to true, the if condition will not continue to check if $col!=='item' is true. The if condition in this case with 'or' also know as ||, will check from left to right which one is true, once it finds it, it will exit the condition so to speak. If you need to check if both have to be true, use &&. Link to comment Share on other sites More sharing options...
funbinod Posted June 9, 2014 Author Share Posted June 9, 2014 To add to Don Jajo's post, if $col !== 'name' evaluates to true, the if condition will not continue to check if $col!=='item' is true. The if condition in this case with 'or' also know as ||, will check from left to right which one is true, once it finds it, it will exit the condition so to speak. If you need to check if both have to be true, use &&. my requirement is for the either case, as u said, from left to right and when it finds only one case TRUE it should stop checking further and execute the query. if ($col !== 'name') is true stop and execute the query. if ($col !== 'name') is false check if ($col !== 'item') is true and if it is true execute the query. and if both are false escape the query and move forward... could this be done with @Don Jajo's suggestion? Link to comment Share on other sites More sharing options...
Don Jajo Posted June 9, 2014 Share Posted June 9, 2014 Use "and" instead of "or" Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now