我只是想知道下面的代码是否最有效地使用 php/sql 中的数据库信息填充下拉列表。 //GET ALL SONGS FROM DATABASE $query = $dbConn->query("SELECT track_id, track_title FROM track"); echo '<select class="feild" name="songDrop">';//MAKE THE DROPDOWN echo '<option value="none">Choose the Song to add</option>'; // Loop through the query results, displaying the options one by one while ($row = $query->fetch_assoc()) { echo '<option value="'.$row['track_id'].'">'.$row['track_title'].'</option>'; } echo '</select>';
1 回答
慕田峪7331174
TA贡献1828条经验 获得超13个赞
尝试这个 :
//GET ALL SONGS FROM DATABASE
$query = $dbConn->query("SELECT track_id, track_title FROM track");
echo '<select class="feild" name="songDrop">';//MAKE THE DROPDOWN
echo '<option value="none">Choose the Song to add</option>';
// Loop through the query results, displaying the options one by one
while ($row = mysqli_fetch_array($query)) {
echo '<option value="'.$row['track_id'].'">'.$row['track_title'].'</option>';
}
echo '</select>';
- 1 回答
- 0 关注
- 81 浏览
添加回答
举报
0/150
提交
取消