検索フィールドに入力された内容に基づいてデータを取得する基本的な 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
?>