搜索栏结果过滤php

时间:2017-01-28 07:06:51

标签: php database mysqli

我正在建立一个电子商务网站。我想根据搜索框中的文字过滤产品。

'产品'表:

products
id| type_id | brand_id | cat_id | title| desc

我想检查result_name或brand_name或cat_name中是否存在result_text,并根据它显示所有产品。

1 个答案:

答案 0 :(得分:1)

我将使用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 */
相关问题