MySQL查询多个复选框值 [英] MySQL query for multiple checkbox values

查看:53
本文介绍了MySQL查询多个复选框值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新来的复选框.我想让用户根据复选框列表表示的三个可能的过滤器进行搜索.例如,如果我使用下面的表格,我希望用户能够包含(红色或蓝色)和大尺寸的所有形状.我已经找到的有关复选框查询的建议尚未完全解决此问题.我可以用一个MySQL查询来做到这一点吗?

I'm new to checkboxes. I want to let users do a search based on three possible filters represented by checkbox lists. For example, if I used the form below, I'd like the user to be able to include all shapes that are (red or blue) and large. The advice I've been able to find about checkbox queries hasn't hit this issue exactly. Is there a way I can do this with one MySQL query?

<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 = implode(,",$ _GET ['color']);

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

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

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

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

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

查询:

从表中选择*,其中颜色为($ colors)或大小为($ size)或形状为($ shape);

select * from table where color in ($colors) or size in ($size) or shape in ($shape);

您需要添加条件以选中全部包含". (如果用户检查,请选择所有变量,包括所有检查值)

You need to add condition to check Include all. (if user check select all the variables include all the checking values)

这篇关于MySQL查询多个复选框值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆