从 mysql 中检索超过 3 个数据到复选框中 [英] Retrieve more than 3 data's from mysql into checkbox

查看:46
本文介绍了从 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 个数据到复选框中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆