Jump to content

Multiple if conditions not working


lnenad

Recommended Posts

($res['cat']!="Nothing" || $res['cat']!="Something"){ do some code }

 

That for some reason is not working and the code gets executed even though $res['cat']!="Something" . When i try the conditions separately it doesn't. I don't understand what's wrong ?  :confused::shrug:

Link to comment
Share on other sites

You need to provide some more information, like what is $res['cat']? As if it is not Something or Nothing it will execute. Perhaps you wanted an AND instead of an OR?

 

I need OR :). $res is a mysql return array ['cat'] is a column. It represents some categories, 5 of them, and some (3) have additional info to be displayed, 2 of them don't so i don't want to display that additional information when the categories selected aren't those 3. If it's NOT EQUAL 4 OR 5 display the info, otherwise don't display it, hence the 

 

IF ($res['cat']!="Nothing" || $res['cat']!="Something"){ do some code }

Link to comment
Share on other sites

:) Give and a try. Because if it is equal to anything but 4 or 5 you want to display the information:

 

if ($res['cat'] != "Nothing" && $res['cat'] != "Something") {

 

That is how you would display not equal to "4 or 5" just because there is an or in that statement does not mean that is what you want to use. Give it a try.

 

The and statement, both those conditions have to be true to execute. So the cat cannot equal nothing OR something. If it does it will not execute. Your OR statement was always executing because if $res['cat'] was not "something" or not "nothing" then it would execute it.

 

Hope that makes sense, kind of a hard thing to explain, but basically that OR statement you had originally would execute no matter what, because $res['cat'] cannot be both of those. 

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.