【发布时间】:2017-01-28 07:06:51
【问题描述】:
我正在创建一个电子商务网站。我想根据搜索框中的文字过滤产品。
“产品”表:
products
id| type_id | brand_id | cat_id | title| desc
我想检查 type_name 或 brand_name 或 cat_name 中是否存在 result_text 并显示基于它的所有产品。
【问题讨论】:
我正在创建一个电子商务网站。我想根据搜索框中的文字过滤产品。
“产品”表:
products
id| type_id | brand_id | cat_id | title| desc
我想检查 type_name 或 brand_name 或 cat_name 中是否存在 result_text 并显示基于它的所有产品。
【问题讨论】:
我会在你的数据库中使用 MySQL,并且 type_id、brand_id 和 cat_id 是外键。
在 MySQL 中,您有一个不错的关键字 LIKE。然后您还可以使用连接来帮助您从相关表中获取数据
所以你需要一个类似的查询
SELECT products.*, types.* /* other tables here */
FROM products LEFT JOIN types on products.type_id = types.id /* other joins here */
WHERE types.type_name LIKE '%/* variable here */%' OR brands.brand_name LIKE '%/* variable here */%' /* other conditions */
【讨论】: