如何从选择下拉列表中的数据库中获取数据
我正在尝试构建一个宾果游戏,我想在选择(下拉列表)中显示我以前的记录!如何从选择下拉列表中的数据库中获取数据 ---下面是我的php文件
<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>
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>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
为什么在 php 代码后面添加选项结束标记。不应该是这样的吗。
Why have you added option end tag after php code. Isn't it supposed to be like this.
首先从数据库中选择旧的选定名称,例如“哈利·波特”
然后使用 if 条件在 while 循环中选择旧的,
谢谢
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
首先,您必须正确关闭第一个选项标签。
另外,您可能希望选项值是数据库中的 id 列。
请使用表中正确的列名称。
但它应该是这样的:
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: