我一直在尋找一個選擇框,可用於多選,以確定我想在我的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,回聲給我: 入站Summerside 這在同一行。
我使用查詢來獲取數據庫中的名稱(query1)。 我想現在使用這些「名稱」,去我選擇我的例子(入站和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
,但沒有幫助。我是否需要使用價值和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()
您的代碼很容易受到SQL注入式攻擊。您應該使用[mysqli](http://php.net/manual/en/mysqli.quickstart.prepared-statements.php)或[PDO](http://php.net/manual/en/pdo.prepared- statement.php)按照[本文]中描述的準備語句(http://stackoverflow.com/questions/60174/how-can-i-prevent-sql-injection-in-php)。 –
因爲你有一個位置數組,你可能想[閱讀此](http://stackoverflow.com/questions/907806/passing-an-array-to-a-query-using-a-where-clause)讓mysql做這個工作? – OldPadawan
mysqli它已經在另一個網頁上調用cnx_db。 部分是,我會去讀 – Nexis