MySQL查询多个复选框值


MySQL query for multiple checkbox values

我是复选框的新手。我想让用户根据复选框列表表示的三个可能的过滤器进行搜索。例如,如果我使用下面的表单,我希望用户能够包括所有(红色或蓝色)和大的形状。我能找到的关于复选框查询的建议并没有完全解决这个问题。有没有一种方法可以用一个MySQL查询做到这一点?

<form action="dbdquery.php" method="get">

<p>
Color:
<br/>
<input type="checkbox" name="color[]" value="Include All" checked/> Include All<br/>
<input type="checkbox" name="color[]" value="Red"/> Red<br/>
<input type="checkbox" name="color[]" value="Blue"/> Blue<br/>
<input type="checkbox" name="color[]" value="Yellow"/> Yellow<br/>
</p>
<p>
Size:
<br/>
<input type="checkbox" name="size[]" value="Include All" checked/> Include All<br/>
<input type="checkbox" name="size[]" value="Small"/> Small<br/>
<input type="checkbox" name="size[]" value="Medium"/> Medium<br/>
<input type="checkbox" name="size[]" value="Large"/> Large<br/>
</p>

<p>
Shape:
<br/>
<input type="checkbox" name="shape[]" value="Include All" checked/> Include All<br/>
<input type="checkbox" name="shape[]" value="Round"/> Round<br/>
<input type="checkbox" name="shape[]" value="Square"/> Square<br/>
<input type="checkbox" name="shape[]" value="Irregular"/> Irregular<br/>
</p>

    <input type="submit" value="Search">
</form>

试试这个:

使用内爆功能,

$colors=内爆(",",$_GET['color']);

$size=内爆(",",$_GET['size']);

$shape=内爆(",",$_GET["shape']);

查询:

从表中选择*,其中color in($colors)或size in($size)或shape in($shape);

您需要添加条件以选中Include all。(如果用户检查选择所有变量,包括所有检查值)