简体   繁体   English

从SQL查询中排除两个变量

[英]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 display=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'. 如您所见,我只包含了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. verify = NULL将永远不会匹配,因为根据定义,结果为NULL,实际上是不匹配。 Testing NULL for equality really ought to be a syntax error. 测试NULL是否相等确实应该是语法错误。

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. 是的,您应该在WHERE子句中使用AND关键字。 You should also give it a try, and let us know if there are any issues. 您还应该尝试一下,如果有任何问题,请告知我们。

尝试一下“喜欢”:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM