如何在MYsql中存储复选框?
我是新手。我有这个编码...如何存储到Mysql中以及如何从数据库中检索?
<input type="checkbox" name="like" value="yes"/>Yes
<input type="checkbox" name="like" value="no"/>No
我怀疑如果我同时选择两个框意味着会发生什么? 请解释一下...提前致谢..
Am Newbie.I have this coding...How to store into Mysql and How to Retrieve from the Database?
<input type="checkbox" name="like" value="yes"/>Yes
<input type="checkbox" name="like" value="no"/>No
am doubt with if i select both 2 box means what will happen?
Please Explain...Thanks in Advance..
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
如果您对逗号分隔值没有问题,
我的答案将帮助您
简单地在字段中使用数组名称,
然后
php" rel="nofollow">如果选中两个框,则
结果将是
yes,no
将您的列设为 varchar
然后做平常的事情来存储
If you have no problem with comma separated values
my answer will help you
simple use array name to your field
then implode it with comma
if two box is checked then
result will be
yes,no
make your column in varchar
Then do usual stuff to store
yourscript.php:
retreive.php:
如果您选择这两个字段,它将保存最新的选择。
你想要收音机(可能)
yourscript.php:
retreive.php:
If you select both fields, it will save the latest select.
You want radio (probably)
您可能一开始就不想这样做。您真正想要使用的是用于是/否值的单选按钮。否则,你会遇到问题。
You probably don't want to be doing this in the first place. What you really want to be using is radio buttons for yes/no values. Otherwise, you're going to run into problems.
您可以像这样
使用
serialize();
函数存储在数据库中。unserialize()
返回带有键的相同数组。you can use like this
to store in db use
serialize();
function.unserialize()
return the same array with keys.