duanditang2916
2019-04-26 13:26
浏览 295
已采纳

如何在WHERE子句上使用多个OR?

I am having a problem with my MYSQL statement

Warning : mysqli_num_rows() expects parameter 1 to be mysqli_result, bool given in C:\Users\R.B.Lara\Documents\My Projects\focalnews\index.php on line 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"];
    }
}
?>

Any Idea please?

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • douchuo9476 2019-04-26 13:29
    已采纳

    ORDER BY and LIMIT should be goes at the end.

    You can use the multiple conditions in OR as follows

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

    Your query should be

    $sqltype = "SELECT * FROM focalnews_items WHERE likes >= 5 OR love >= 5 OR informative >= 5 ORDER BY datime ASC limit $last,20";
    
    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题