我正在尝试为我的网上商店做一个过滤器。 我有以下查询
$column = mysqli_query($link, "SELECT brand FROM shields WHERE
brand=".$brand." ORDER BY id DESC LIMIT ".$offset. "," . $itemsPerPage);
我希望$brand
等于1
,2
和3
默认显示我商店中的每件商品,当我过滤时,它会更改{ {1}} $brand
,1
或2
使用此代码
3
答案 0 :(得分:0)
你可以这样做:
if(isset($_POST["brand"])){
$brand = $_POST["brand"]; // filter_input(INPUT_GET, 'brand', FILTER_VALIDATE_INT);
$filterByBrand = "and brand =".$brand;
}
else{
$brand = "1,2,3";
$filterByBrand = "and brand in(".$brand.")";
}
$column = mysqli_query($link, "SELECT brand FROM shields WHERE 1=1
".$filterByBrand." ORDER BY id DESC LIMIT ".$offset. "," . $itemsPerPage);