需要通过 mysql 结果检查 html 复选框 [英] Need html checkbox to be checked by mysql result
本文介绍了需要通过 mysql 结果检查 html 复选框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的需要是通过 mysql 选择结果选中一个复选框...
My need is to check a checkbox by mysql select result...
这是我的mysql表
username | hobbies
----------------------------
abc | reading painting
当我选择用户名abc"并提交时,它会进入编辑页面..
When I select username 'abc' and submit,it goes to edit page..
在那个页面我需要编辑爱好..
In that page I need to edit hobbies..
<html>
<body>
<input type="checkbox" name="hobbies[]" value="reading">Reading
<input type="checkbox" name="hobbies[]" value="painting">painting
<input type="checkbox" name="hobbies[]" value="gaming">gaming
</body>
<html>
当我选择'abc' 爱好阅读和绘画时,只有第一个 &必须选中第二个复选框...我怎么能用 php,mysql 做到这一点???请帮忙.....
When I select 'abc' with hobbies reading and painting,only the first & second checkboxes must be checked...How can i do that with php,mysql??? pls help.....
推荐答案
首先将数据库记录拆分成单独的数组条目
First split the database record to seperate array entries
<?php
$hobbies = explode(" ", $mysql_result['hobbies']);
?>
然后检查每个值是否数组包含该值并将复选框设置为已选中
Then check for each value if the array contains the value and set the checkbox to checked
<input type="checkbox" name="hobbies[]" value="reading" <?php if(in_array("reading", $hobbies)) echo "checked=\"checked\""; ?>>Reading
这篇关于需要通过 mysql 结果检查 html 复选框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文