我有一個基本的SQL查詢,它基於在搜索字段中輸入的內容獲取一些數據 - 我已經將選擇框從數據庫中的列填充 - 我我想要做的是,當這個改變/發佈時,它會更新已經發現的結果,即通過遊戲的「流派」進一步鑽取它們。通過選擇/下拉框過濾的搜索結果
下面的代碼我已經有
echo "<select id='dropdown' name='dropdown' class='dropdown'>";//creates select HTML element
$stmt = $dbh->prepare('SELECT genre_name FROM genre'); //prepares sql query
$stmt->execute(); //executes query
while($row = $stmt->fetch(PDO::FETCH_ASSOC)) { //fetches data in associative array
echo "<option>{$row['genre_name']}</option>"; //inputs data found into select as an option
}
echo "</select>";
echo '<input type="submit" value="Filter" id="filter" name="filter" class="filter">';
if(!isset($_POST['filter']))//check if filter genre has been pressed
{
echo ("<h4>Please select a genre</h4>"); //if not show this
}
else { //otherwise if it has...do this
echo ("<h4>Your results have been filtered</h4>");
$dropvalue = $_POST['dropdown']; //sets variable of value of dropdown box
$dbh = config();
//sorting function, want to further drill search results by genre
$stmt = $dbh->prepare("SELECT * FROM consoles, games, genre WHERE genre.genre_name = :dropvalue");
$stmt->bindValue(':dropvalue','%'.$dropvalue.'%');
$stmt->execute();
while ($row = $stmt->fetch())
{
echo "<ul>";
echo "<a href='details.php?game_id=".$row['game_id']."'>".$row['game_name']."</a>";
echo "</ul>";
}
}
$dbh = NULL; //terminates connection to database
?>
可能重複的解決方案](http://stackoverflow.com/questions/7137357/cascade-dropdown-list-using-jquery-php) –
那麼你有什麼問題?你從來沒有真正提出過一個問題。 – Pitchinnate
我遇到的問題是已經填充了下拉菜單,我怎麼去限制已經返回的數據,進一步通過用戶做出的選擇? – cstones88