MySQL:我需要两个以上的OR条件!我怎样才能做到这一点?

时间:2022-04-03 09:02:13

I am quite a beginner with mySql and I am facing a problem. I am creating a search bar and I want to select an item from a database whenever the keyword match with the color, the brand etc...

我是mySql的初学者,我遇到了一个问题。我正在创建一个搜索栏,我想在关键字与颜色,品牌等匹配时从数据库中选择一个项目...

Here is my code

这是我的代码

$sql = "SELECT title, description, picture FROM clothes 
        WHERE type LIKE :keyword;
        OR color LIKE :keyword;
        OR brand LIKE :keyword;
        OR material LIKE :keyword";

So far I can only find items from the type request... The color, brand etc are not working. Thanks for your help.

到目前为止,我只能从类型请求中找到项目...颜色,品牌等不起作用。谢谢你的帮助。

1 个解决方案

#1


0  

You have semicolons at the end of the lines within the query. Remove them:

您在查询中的行末尾有分号。删除它们:

$sql - "SELECT title, description, picture
        FROM clothes 
        WHERE type LIKE :keyword OR
              color LIKE :keyword OR
              brand LIKE :keyword OR
              material LIKE :keyword";

#1


0  

You have semicolons at the end of the lines within the query. Remove them:

您在查询中的行末尾有分号。删除它们:

$sql - "SELECT title, description, picture
        FROM clothes 
        WHERE type LIKE :keyword OR
              color LIKE :keyword OR
              brand LIKE :keyword OR
              material LIKE :keyword";