本文介绍了从mysql检索超过3个数据到复选框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要从mysql
检索兴趣爱好名称并将其显示在复选框中.我完成了下面给出的代码.但是它仅显示复选框,而不显示任何爱好名称.请帮忙.
I need to retrieve the hobbies name from mysql
and display it in check boxes. I done the below given code. But it displays just check box and not any hobby names. Please help.
$query = "SELECT * FROM hobbies";
$result = mysqli_query($con, "$query");
while ($r=mysqli_fetch_array($result))
{
$hobby=$r["hobby_name"];?>
<input type='checkbox' name='check[]' value='$hobby'>
}
推荐答案
您需要在每个复选框旁边添加简单文本$hobby
.
You need to add simple text $hobby
next to every checkbox.
更正的代码:
$query = "SELECT * FROM hobbies";
$result = mysqli_query($con, "$query");
while ($r=mysqli_fetch_array($result)) {
$hobby=$r["hobby_name"];
?>
<input type='checkbox' name='check[]' value='<?php echo $hobby;?>'> <?php echo $hobby;?>
<?php
}
这篇关于从mysql检索超过3个数据到复选框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!