如何在WHERE子句上使用Multiple OR?

时间:2019-04-26 13:26:16

标签: php mysql

我的MYSQL语句有问题

  

警告   :mysqli_num_rows()期望参数1为mysqli_result,布尔值在   C:\ Users \ RBLara \ Documents \ My Projects \ focalnews \ index.php   在线   188

$sqltype = "SELECT * FROM focalnews_items ORDER BY datime ASC limit $last,20 WHERE (likes >= 5 OR love >= 5 OR informative >= 5)";

$resulttype = mysqli_query($conn, $sqltype);

if (mysqli_num_rows($resulttype) > 0) {
    while($row = mysqli_fetch_assoc($resulttype))
    {
        $profile_pic = $row["profile_pic"];
        $author = $row["author"];
        $message = $row["message"];
        $likes = $row["likes"];
        $love = $row["love"];
        $informative = $row["informative"];
        $datime = $row["datime"];
        $joined_date = $row["joined_date"];
    }
}
?>

有什么想法吗?

1 个答案:

答案 0 :(得分:0)

  

ORDER BY和LIMIT应该放在末尾。

您可以按以下方式在OR中使用多个条件

WHERE  likes >= 5 OR love >= 5 OR informative >= 5

您的查询应该是

$sqltype = "SELECT * FROM focalnews_items WHERE likes >= 5 OR love >= 5 OR informative >= 5 ORDER BY datime ASC limit $last,20";