我想在html表单加载时加载下拉列表的选项。我已经知道当我选择第一个下拉列表并加载第二个时如何操作。但是当页面加载如何执行此操作时。我们对此给予了善意的考虑非常感谢。
答案 0 :(得分:1)
您可以尝试使用以下内容从数据库加载deopdownlist选项
<?php
$con=mysqli_connect("localhost","user","password","db_name");
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result = mysqli_query($con,"SELECT * FROM table_name");
echo '<select id="select_1">';
while($row = mysqli_fetch_array($result)) {
echo '<option value="'.$row['column_name'].'">'.$row['column_name'].'</option>';
}
echo '</select>';
mysqli_close($con);
?>