如何在表的一列中插入两个不同的复选框值 [英] how to insert two different checkbox values in one column of table

查看:74
本文介绍了如何在表的一列中插入两个不同的复选框值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个语言的两个复选框。如果用户选中了它们,那么如何将两个选中的值保存在表的一个语言列中。

i am having two checkboxes for two languages. If user checked both of them then how to save both checked values in one language column of table.

推荐答案

简单的答案是:你不应该!



您应该使用在主表上具有外键的附加表,并根据复选框将一行或多行插入到语言中。这很容易扩展(添加新语言只更改用户界面),可以排序,订购,加入其他表等...



如果你绝对要放他们进入单场,你最好的赌注是逗号分隔列表。这种严重的缺点:每次你必须访问该字段时,你必须解析值,你不能通过它搜索或按顺序搜索,你不能加入其他表等...



甚至为每种语言添加一个单独的列(也是糟糕的设计,希望你永远不必适应新语言)然后将所有内容放入单列中会更好。



如果这有帮助,请花时间接受解决方案。谢谢。
Simple answer is: YOU SHOULD NOT!

You should use additional table that will have foreign key on the main table and insert one or more rows into languages depending on the checkboxes. This is easily scalable (adding new languages changes only user interface), can be sorted, ordered, joined to other tables etc...

If you absolutely have to put them into single field, your best bet is comma separated list. Drawbacks of this severe: each time you have to access the field, you have to parse the values, you cannot search by it or order by it, you cannot join to other tables etc...

It would be better even to add a column separate for each language (also bad design, hope that you will never have to adapt to new language) then to put everything into single column.

If this helps please take time to accept the solution. Thank you.


在选择了另一种语言的情况下插入另一行或在列中存储两个以逗号分隔的复选框值。
Insert another row with another language selected or Store two checkbox values comma separated in column.


你可以使用像'^这样的一些分隔符'并保存数据。



ex;

存储在db中的数据将是这样的

lang1 ^ lang2 。





当你想要访问这些值时你可以像这样拆分



将整个值转换为一个名为lang的变量,之后你可以进行以下编码



lang1 = lang.Split('^')。

lang2 = lang.Split('^')。最后;
you can use some delimeters like '^' and save data.

ex;
data stored in db would be like this
lang1^lang2.


when you want to access those values you can split it like this

take the whole value into one variable called lang after that you can do the below coding

lang1= lang.Split('^').First;
lang2= lang.Split('^').Last;


这篇关于如何在表的一列中插入两个不同的复选框值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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