开发者

Exclude TWO variables from SQL query

I know this is going to be answered in all of two seconds, but I can't find it anywhere online. I need to omit two things from my query...

  1. Where displa开发者_运维百科y=no
  2. Where verified=null

I don't want their information showing up if they've set their display to "no" or they haven't been verified (I put in a "yes" when they've been verified")

As you can see, I only included those with display='yes'. How do I get the other part?

$query = "SELECT * FROM $table WHERE display='yes'"

Do I just do this?

SELECT * FROM $table WHERE display='yes' AND verified='yes'"


WHERE display<>'no' AND verified IS NOT NULL

verified = NULL will never match, as by definition the result is NULL which is in effect a nomatch. Testing NULL for equality really ought to be a syntax error.


Thanks for the comments everyone. This is what I ended up going with:


$query = "SELECT * FROM $table WHERE display='yes' AND verified='yes'";
$result = mysql_query($query);
    if (!$result) {
die('Invalid query: ' . mysql_error());

Worked like a charm! Excluding those who said "yes" to "please display my info" and "yes" to those that had been verified. Sorry for the confusion in my initial question!


Yes, you should use the AND keyword in the WHERE clause. You should also give it a try, and let us know if there are any issues.


Try it out with 'LIKE':

SELECT * FROM $TABLE WHERE DISPLAY LIKE 'yes' AND VERIFIED LIKE 'yes'
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜