I am trying to build a Bingo game, where I want to display my previous records in a select(dropdown)!! how do I fetch my data from database in select dropdown list
—below is my php file
<html>
<style>
#rec_mode{
background-image: url('register.png');
background-size: 100% 100%;
width: 100px;
height: 50px;
border: none;
outline: 0px;
-webkit-appearance: none;
}
</style>
<body>
<select name = "select_history" id="rec_mode">
<option selected="true" disabled="disabled">
<?php
require_once 'config.php';
// $hist = mysqli_query($mysqli, "SELECT name FROM `movie_names` ORDER BY movieID DESC");
$hist = mysqli_query($mysqli,"SELECT m.name FROM movie_names m INNER JOIN host_table ht WHERE m.movieID = ht.random_num ORDER BY ID DESC");
while ($row = $hist->fetch_assoc())
{
echo "<option value="select_history">".$row['name']."</option>";
}
?>
</option>
</select>
</body>
</html>
3
Answers
Why have you added option end tag after php code. Isn’t it supposed to be like this.
First select old selected name from DB eg "harry potter"
then use if condition to select inside while loop selected for old one
Thank You
First, you have to close that first option tag properly.
Also, you might want the option value would be the id column from the db.
Please use the correct column names from your tables.
But it should be something like this: