MySQL WHERE东西= $ something和$ something =默认情况下的每个值

时间:2015-06-28 16:51:29

标签: php mysql mysqli

我正在尝试为我的网上商店做一个过滤器。 我有以下查询

$column = mysqli_query($link, "SELECT brand FROM shields WHERE
brand=".$brand." ORDER BY id DESC LIMIT ".$offset. "," . $itemsPerPage);

我希望$brand等于123默认显示我商店中的每件商品,当我过滤时,它会更改{ {1}} $brand12使用此代码

3

1 个答案:

答案 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);