本文介绍了未定义的索引:PHP中的复选框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
用于选择流派类型的用户的复选框列表。类型输入来自数据库。因为sql会在数组中返回结果,所以for循环获取所有值并将它们放入复选框。错误来自循环中的第三行。它显示未定义的索引类型
我尝试过:
A list of checkbox for user to select genre type. The genre input is from database. Because the sql will return the result in an array, a for loop to get all the values and make them into a check box. The error come from third line in the loop. It show undefined index genre
What I have tried:
<div class="list-group">
<h3>Genre</h3>
<?php
$search_genre = "SELECT DISTINCT(genre) FROM movie_db WHERE product_status ='1' ORDER BY movieid DESC"
$statement = mysqli_query($conn,$search_genre);
$result = mysqli_fetch_all($statement);
foreach ($result as $row){
?>
<div class="list-group-item checkbox">
<label><input type="checkbox" class="common_selector genre" value="<?php echo$row['genre'];?> > <?php echo $row['genre'];?></label>
</div>
<?php
}
?>
推荐答案
这篇关于未定义的索引:PHP中的复选框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!