简体   繁体   English

在数据库中保存带有复选框值的清单

[英]Saving a checklist with values of checkboxes in a database

For a web application I need to make some kind of checklist for users. 对于Web应用程序,我需要为用户制作某种清单。 The checklist is administrated by a special administrator account and only he can edit the checklist. 该清单由一个特殊的管理员帐户管理,只有他才能编辑该清单。 Each user has it's own checklist with certain conditions which has to be checked when that condition is met. 每个用户都有自己的带有特定条件的清单,必须满足该条件。 Also I added a textbox for any comments (if there are any) 我还添加了一个文本框,用于注释(如果有的话)

I constructed a few tables in a MySQL database: A users database which has the data of all registered users 我在MySQL数据库中构造了一些表:一个用户数据库,其中包含所有注册用户的数据

A table called checklist properties with the following columns: 带有以下各列的称为检查表属性的表:

property_idnr | type | description

Next a table which links the user with the property with the following columns: 接下来是一个表,该表使用以下各列将用户与属性链接:

link_idnr | user_idnr | property_idnr | comments

Now my question is, did I set this up properly? 现在我的问题是,我是否正确设置了此设置? Also, I am having a bit of an issue with the Query's.. what is the best way to store these values in the database? 另外,查询还有一点问题。在数据库中存储这些值的最佳方法是什么?

I hope someone is able to help me out with this, if you need any more information, please ask! 我希望有人能够帮助我解决这个问题,如果您需要更多信息,请询问!

Your schema looks reasonable. 您的架构看起来很合理。 To get the list for a given user, you would use a query like this: 要获取给定用户的列表,可以使用如下查询:

select clp.type
from CheckListLink cll join
     CheckListProperties clp
     on cll.property_id = clp.property_id
where cll.user_id = <user_id>

What I would suggest adding is an ordering column into the CheckListLink table. 我建议添加的是CheckListLink表中的排序列。 Different users may have their check list ordered in different ways. 不同的用户可能以不同的方式对他们的清单进行排序。 Also, I would add a datetime column to all the tables, so you know when the records were created. 另外,我将在所有表中添加一个datetime列,以便您知道何时创建记录。

Storing the values . 存储值。 . . Well, you need a way to set up the possible items in the check list. 好吧,您需要一种在检查清单中设置可能项目的方法。 And, then you need a way for users to choose the items they want in their check list. 然后,您需要一种让用户在检查清单中选择所需项目的方法。 From a database perspective, this is just a question of various insert statements (perhaps deletes as well). 从数据库的角度来看,这只是各种插入语句(也许也删除)的问题。 The bigger challenge is on the UI side. 更大的挑战是在UI方面。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM