!= operator question

the code works if I remove the or portion but I need to check to make sure its not either 9 or 10.  I am not sure what I am doing wrong
if(($row['cnid'] != '9') || ($row['cnid'] != '10')) {

Open in new window

Who is Participating?
zappafan2k2Connect With a Mentor Commented:
Another way to write it would be
if (!($row['cnid'] == '9' || $row['cnid'] == 10)) {

Open in new window

if that makes more sense.

It's all about the logic.
Try && instead of ||
Lukasz ChmielewskiCommented:
So to be complete
if(($row['cnid'] != '9') && ($row['cnid'] != '10'))

if the cnid is not 9 AND is not 10 - do something
Mind that you're comparing the string value '9' and '10'
To check if the $row['cnid'] is not the value and the type integer you would use !==
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Lukasz ChmielewskiCommented:
the logic is the same in result :P
if NOT (9 OR 10) equals if NOT 9 OR NOT 10
Ray PaseurCommented:
The "or" condition is evaluated from left to right in this sequence.  So if you give it 10, the if() statement will be satisfied that 10 is not 9, and no further tests will be done.  That is why you want the && instead of the || here.
iceman19330Author Commented:
thank you
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.