在数据库中存储多个复选框和radiobutton值? [英] store multiple checkbox and radiobutton value in database?

查看:123
本文介绍了在数据库中存储多个复选框和radiobutton值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hii,

我想知道在一列中存储复选框值的代码以及如何从数据库中检索它们。同时适用于多个单选按钮。

Hii,
I want to know code of storing checkboxes value in one column and also how to retrieve them from database.Same applies for multiple radiobuttons.

推荐答案

如果你想在一个列中存储多个复选框值,那么你应该将复选框的集合转换为二进制数



例如。

CHKBOX1 = 0

CHKBOX2 = 1

CHKBOX4 = 1

CHKBOX8 = 1



存储在Db中的数字将是14(即1 * 8 + 1 * 4 + 1 * 2 + 0 * 1)



要设置数据库中的值,您需要反转该过程 - 即取数字14

获取二进制表示并相应地设置复选框。
If you want to store multiple checkbox values in a single column then you should turn the collection of checkboxes into a binary number

eg.
CHKBOX1 = 0
CHKBOX2 = 1
CHKBOX4 = 1
CHKBOX8 = 1

The number to store in the Db would then be 14 (i.e. 1*8 + 1*4 + 1*2 + 0*1)

To set the values from the database you need to reverse the process - i.e. take the number 14
get the binary representation and set the checkboxes appropriately.


这篇关于在数据库中存储多个复选框和radiobutton值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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