Where 子句中的多个条件,打破第二个条件


Multiple Conditions in Where Clause, breaking with second condition

这是一个非常简单的问题。 我一定只是在做一些愚蠢的事情:

此查询回显出行 ID 号:

$query = "SELECT * FROM userpage WHERE uploaderrating = $rating";
        $result = mysql_query($query);
        $row1= mysql_fetch_array($result);
            echo $row1[id];

当我添加一个附加条件时(即使 SQL 数据库中肯定满足该条件,回显也会产生任何东西(即变量为空)。 失败的代码是:

$query = "SELECT * FROM userpage WHERE uploaderrating = $rating and reviewer = NULL";
        $result = mysql_query($query);
        $row1= mysql_fetch_array($result);
            echo $row1[id];

你不能使用

reviewer = NULL

您需要使用

reviewer IS NULL

NULL 是一个未定义的值,所以它不等于任何东西;所以你需要使用 IS 来查找它。

你应该使用

 $query = "SELECT * FROM userpage WHERE uploaderrating = $rating and reviewer IS NULL";
    $result = mysql_query($query);
    $row1= mysql_fetch_array($result);
        echo $row1[id];

我希望它有效。

我所知,空值是用IS验证

  • 。其中 xxx 为空
  • 。其中 xxx 不为空