我有一个基本的 SQL 查询,它根据输入到搜索字段中的内容获取一些数据 - 我已经放置了一个从数据库中的列填充的选择框 - 我想做的是当它被改变时/post,它会更新已经找到的结果,即通过游戏的“类型”进一步深入研究它们。
这是我已经拥有的代码
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
?>