如何将所选值从选择框传递到研究

时间:2017-04-06 14:31:01

标签: php mysql database search

我一直在寻找一个可以用于多项选择的选择框,以确定我想在research中找到哪个位置,这是database的附件。所以,在这里,我发现了这一点:

我在我的几个位置放了一个选择框:

<select name="SelectLocation[]" MULTIPLE="yes">
<option value="1">Inbound</option>
<option value="2">OutBound</option>
<option value="3">Training Room</option>
<option value="4">Summerside</option>
<option value="5">Alberton</option>
</select>

我使用foreach给我选择的位置:

foreach ($_GET['SelectLocation'] as $selectedOption){
//echo $selectedOption."\n";

$query1="select * from location where location_id=$selectedOption";
$info=info_query($query1);
$nomLocation=$info['location'];
$Location .= $nomLocation."\n";
}
echo $Location;

现在,如果我选择Inbound和Summerside,回声会给我: 入境萨默赛德 这在同一行。

我使用查询来获取数据库中的名称(query1)。 我现在想要使用那些“名称”,我选择了我的例子(Inbound和Summerside),做我的搜索,它只选择所选的位置,而不是另一个,所以我在我的查询中做了这个:

location.location like".$Location;
$query="select computer.computer_id,
computer.computer_name,
computer.product_key,
computer.model,
computer.serial_number,
`status`.`status`,
computer.starphone,
computer.inst_id,
computer.did,
computer.macaddress,
software.description,
vendor.vendor_name,
location.location,
department.department,
jack.jack_number
from computer
inner join computer_vendor on computer.computer_id=computer_vendor.computer_id
inner join vendor on computer_vendor.vendor_id=vendor.vendor_id
inner join `status`on computer.status_id=`status`.status_id
inner join software on computer.software_id=software.software_id
inner join jack on jack.computer_id=computer.computer_id
inner join location on location.location_id=jack.location_id
inner join department on department.dept_id=jack.dept_id
where computer.computer_name like '%".$critere."%' and location.location like".$Location;

我的问题是:我用我的例子Inbound和Summerside进行研究,它没有给我任何录音。 这是因为我的位置在一条线上,他可以在数据库中找到?我尝试将%放在$Location之前和之后$critere,但没有帮助。如果没有位置名称,我是否需要使用value和location_id?

我想要的是,我的$Location能够告诉所选择的位置到数据库,并使选择与数据库完美配合,我的研究显示了所选位置和标准所需的所有信息。< / p>

如果需要更多信息,请告诉我,我会提供。

select computer.computer_id, 
computer.computer_name, 
computer.product_key,
computer.model, 
computer.serial_number, 
`status`.`status`, 
computer.starphone, 
computer.inst_id, 
computer.did,
computer.macaddress, 
software.description, 
vendor.vendor_name, 
location.location, 
department.department,
jack.jack_number from computer inner join computer_vendor on computer.computer_id=computer_vendor.computer_id 
inner join vendor on computer_vendor.vendor_id=vendor.vendor_id 
inner join `status`on computer.status_id=`status`.status_id 
inner join software on computer.software_id=software.software_id 
inner join jack on jack.computer_id=computer.computer_id 
inner join location on location.location_id=jack.location_id 
inner join department on department.dept_id=jack.dept_id 
where computer.computer_name like '%52%' and location.location in ()

1 个答案:

答案 0 :(得分:0)

$Location=array();
foreach ($_GET['SelectLocation'] as $selectedOption){
//echo $selectedOption."\n";

$query1="select * from location where location_id=$selectedOption";
$info=info_query($query1);
$nomLocation=$info['location'];
$Location[] = addslashes($nomLocation);
}
$locationConsolidated = "'".join("','", $Location)."'";

并将此$ locationConsolidated用作......

where computer.computer_name like '%".$critere."%' and location.location in ($locationConsolidated)