在选择框中选择多个选项并从数据库中获取结果? [英] Selecting Multiple Options in Selection Boxes and Getting Results From Database?

查看:239
本文介绍了在选择框中选择多个选项并从数据库中获取结果?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我为一个学校项目制作了一个网页,其中有一系列选择框(有些是独立的,有些依赖另一个),然后使用过滤器进行查询.它仍然处于测试模式,并且可以很好地用于单个选择.您可以在此处找到该网页: http://gorevler.awardspace.biz/realdeal03.html

I have made a webpage for a school project where I have a series of selection boxes (some are independent and some are depended on another) to make selections and then apply filter to make a query. It is still in test-mode and working fine for single selections. You can find the webpage here: http://gorevler.awardspace.biz/realdeal03.html

例如,,当我选择地区"中的欧洲",国家"中的奥地利",部门"中的塑料",子部门"中的塑料原料"以及产品"中的聚丁烯"时,单击应用"过滤器,将得出结果.

For example, when I select Europe from Region, Austria from Country, Plastics from Sector, Plastic Raw Materials from Sub-Sector and Polybutylene from Product, and click apply filter it gives out the result.

但是,当我选择地区"中的欧洲和北美",国家"中的奥地利",部门"中的塑料",子部门"中的塑料原材料"以及产品"中的聚丁烯"时,单击应用过滤器"时,只会显示一个结果.但是数据库中有两条记录与此过滤器匹配.因此,它无法识别我的多项选择.关于如何使它起作用的任何建议,以便当我在一个框上进行多个选择并应用过滤器时,它会给出所有结果,包括所有选择?

But, when I select Europe AND North America from Region, Austria from Country, Plastics from Sector, Plastic Raw Materials from Sub-Sector and Polybutylene from Product, and click apply filter, it gives only one result. but there are two records matching this filter in the database. So it does not recognise my multiple selection. Any advice about how I could make it work so that when I make multiple selection on a box and apply filter, it gives all the results including all the selection?

我想这与PHP编码有关,我尝试了不同的方法,但没有成功.由于我不是程序员,所以我似乎不了解问题所在.关于编码的任何建议将不胜感激.

I guess it is something about the PHP coding, and I tried different things but no success yet. Since I am not a programmer, I don't seem to understand where the problem lays. Any advice about the coding would be appreciated.

推荐答案

是因为当您选择两个区域时,查询变为: SELECT ... FROM ... WHERE region ='North America'AND region ='Europe',这意味着您将永远不会从数据库中获得任何结果,因为该区域不能同时为两个区域?如果是这样,则需要这样做,以便对多个选定区域使用"OR"语句.

Is it because when you select two regions your query becomes: SELECT ... FROM ... WHERE region ='North America' AND region = 'Europe' which means you will never get any results from the database as the region cannot be both? If so you'll need to make it so you use "OR" statements for multiple selected regions.

有很多方法可以完成此操作.首先,您需要一种处理您所在区域的多个输入的方法,而不仅仅是在php代码中定义一个输入.基本上,一旦您捕获了多个区域,则查询行是唯一需要更改的行.可以变成:

There are numerous ways of completing this. First of all you need a way of dealing with multiple inputs for your region, rather than just defining the one input in your php code. Basically once you have capture your multiple regiones then your query line is the only line that needs to change. This can become:

$sql = mysql_query("SELECT * from gorevler WHERE region IN ('%$bolge%','%$bolge2%','%bolge3%') AND country LIKE    '%$ulke%' AND sector LIKE '%$sektor%' AND sub_sector LIKE '%$altsektor%' AND product LIKE   '%$urun%'");

$sql = mysql_query("SELECT * from gorevler WHERE (region = '$bolge' OR region = '$bolge2' OR region = '$bolge3) AND country LIKE    '%$ulke%' AND sector LIKE '%$sektor%' AND sub_sector LIKE '%$altsektor%' AND product LIKE   '%$urun%'");

编辑您的最后一个问题的指针:

EDIT with some pointers on your last question:

它只需要来自您的HTML.因此,如果您选择多个区域,那么它将把这些区域发布到您的PHP页面.例如:

It just needs to come from your HTML. So if you select more than one region then it will post these to your PHP page. For example:

<option value="" data-filter-type="" selected="selected" id="europe">Europe</option>

<option value="" data-filter-type="" selected="selected" id="usa">USA</option>

然后在您的PHP中

$bolge=$_POST['europe];
$bolge2=$_POST['usa'];

那可能是最快捷,最肮脏的方法.

That's probably the quick and dirtiest method anyway.

这篇关于在选择框中选择多个选项并从数据库中获取结果?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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