Jump to content
funbinod

problem applying if, or

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

 

 

 

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
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 &&.

Share this post


Link to post
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?

Share this post


Link to post
Share on other sites

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.   Paste as plain text instead

  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.

Loading...

×
×
  • Create New...