Jump to content

problem applying if, or


funbinod
 Share

Recommended Posts

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

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

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...