Home > Backend Development > PHP Tutorial > How to add attribute filtering to the ecshop search page

How to add attribute filtering to the ecshop search page

PHP中文网
Release: 2023-03-01 07:58:01
Original
1721 people have browsed it

You can just replace the hard-coded variables of his sql query with the ones passed through the search.

sql where changes according to the filtering conditions, for example:

$filter['brand'] = isset($_REQUEST['brand']) ? trim($_REQUEST['brand']) : '';//品牌
$filter['price'] = isset($_REQUEST['price']) ? trim($_REQUEST['price']) : '';//价格
$filter['attribute'] = isset($_REQUEST['attribute']) ? trim($_REQUEST['attribute']) : '';//属性

$where = " WHERE 1";
if($filter['brand'] != ''){
    $where .= " AND brand=" . addslashes($filter['brand']);
}
if($filter['price'] != ''){
    $where .= " AND price=" . addslashes($filter['price']);
}
if($filter['attribute'] != ''){
    $where .= " AND attribute=" . addslashes($filter['attribute']);
}
Copy after login
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template