0
我想在一個名爲項目的表中創建一個搜索欄,其中有兩個不同的選項:IID
,Type
。代碼如下。HTML中的選項搜索欄,使用不同的屬性搜索
<h1> Search </h1>
<form name="search" action="items.php" method="get">
Search For: <input type="text" name="item"> in
<select name = "Option">
<option value= "IID"> IID </option>
<option value= "Type"> Type </option>
</select>
<input type="submit" value="search">
</form>
數據存儲爲一個名爲具有屬性IID和類型的Item的表。 然後我做了一個查詢,但我在這裏迷路瞭如何更改select子句。
我在這裏有代碼,以便它搜索用戶輸入的特定類型的項目,但我怎樣才能更改子句,以便它對應於搜索欄中的選項菜單,您可以在其中找到有IID的物品?我需要寫兩個不同的查詢嗎?
任何幫助,將不勝感激!
<?php
//SEARCH by type
$item = ucfirst($_GET["item"]);
if($item != null){
$result = executePlainSQL("select * from item where type = '" . $item . "'");
}
else{
$result = executePlainSQL("select * from item");
}
printItem_byType($result);
//Print result
function printItem_byType($result){
echo '<table>';
echo '<tr><td>IID</td><td>Type</td></tr>';
while ($row = OCI_Fetch_Array($result, OCI_BOTH)) {
echo "<tr><td>" . $row[0] . "</td>
<td><a href = profile.php?IID=" . $row[1] . ">" . $row[1] . "</a></td>
<td><a href= profile.php?type= ". $row[2] . ">" $row[2] . "</td></tr>";
}
echo '</table>';
}