【问题标题】:Where clause in PHP MySQL not working with Like keywordPHP MySQL中的Where子句不适用于Like关键字
【发布时间】:2019-10-19 09:14:19
【问题描述】:

我一直在尝试根据 c_type = "Engineering' 和搜索框中的搜索关键字过滤我的数据。搜索部分工作正常,但查询不工作,它显示了整个结果。

这是为了过滤我的结果

$query1 = mysqli_query($conn, "SELECT * FROM col_details WHERE c_type = 'Engineering' and c_name LIKE '%{$name}%' OR location LIKE '%{$name}%' ");

我试图在我的 col_details 表中显示所有结果,其中 c_type 是 Engineering,而 c_name 或 location 取自搜索框。 搜索框代码工作正常,但它显示的是所有数据,而不是 c_type = 'Engineering' 的数据。

任何帮助表示赞赏。

谢谢。

【问题讨论】:

标签: php mysql


【解决方案1】:

你的 OR 子句应该用括号括起来, 试试这个:

$query1 = mysqli_query($conn, "SELECT * FROM col_details WHERE c_type = 'Engineering' and (c_name LIKE '%{$name}%' OR location LIKE '%{$name}%') ");

希望对你有帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-08-16
    • 2017-04-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-10-03
    相关资源
    最近更新 更多