Jump to content

Multiple if conditions not working


lnenad

Recommended Posts

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 }

:) 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. 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.