[Last Call] Learn how to a build a cloud-first strategyRegister Now


!= operator question

Posted on 2011-05-04
Medium Priority
Last Modified: 2012-05-11
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

Question by:iceman19330
LVL 12

Expert Comment

ID: 35693373
Try && instead of ||
LVL 27

Expert Comment

by:Lukasz Chmielewski
ID: 35693412
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 !==
LVL 12

Accepted Solution

zappafan2k2 earned 2000 total points
ID: 35693414
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.
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

LVL 27

Expert Comment

by:Lukasz Chmielewski
ID: 35693471
the logic is the same in result :P
if NOT (9 OR 10) equals if NOT 9 OR NOT 10
LVL 111

Expert Comment

by:Ray Paseur
ID: 35693592
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.

Author Closing Comment

ID: 35693680
thank you

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

These days socially coordinated efforts have turned into a critical requirement for enterprises.
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses
Course of the Month18 days, 5 hours left to enroll

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question