【发布时间】:2017-04-06 14:31:01
【问题描述】:
我正在寻找一个可用于多项选择的选择框,以确定我想在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,回声会给我: 入境萨默赛德 这在同一行。
我使用查询来获取数据库中的名称(查询1)。 我现在想使用那些“名称”,我选择了我的示例(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 能够告诉数据库选择的位置,并且选择与数据库完美配合,我的研究显示所有必要的信息与所选位置和标准。
如果需要更多信息,请告诉我,我会提供。
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 ()
【问题讨论】:
-
因为你有一个位置数组,你可能想read this 让 mysql 完成这项工作?
-
mysqli已经在另一个网页调用cnx_db中完成了。部分是的,我会去阅读