动态调查应用逻辑 PHP/MSSQL

发布于 2024-10-12 16:30:45 字数 443 浏览 5 评论 0原文

首先,我认为这个问题可以与任何语言相关,但我指定了我使用的语言。

如果我也开始感到无聊,请原谅,但我正在努力找出构建动态调查管理系统的最佳方法。 我的客户基本上对我说,数据必须存储在 MS SQL 中,因为他的客户只有用于 SAS 的 MS SQL 连接器,它将进行报告。

到目前为止我的逻辑是这样的: 第一。设置调查本身,即询问标题、快速概述等。 第二。定义你的问题。 第三。发布调查。

现在,我到目前为止所做的是,当他们“发布调查”时,我为此调查创建了一个专用数据库表,其中将包含回复。 从管理方面来看,他们将无法修改问题,也许是问题标题,但仅此而已。他们无法添加/删除问题。

问题是,创建单独的数据库表是一件好事吗?我唯一担心的是,假设管理员创建了 30 个问题,我将在该专用表中拥有 30 列。为此,SAS 系统可以通过这种方式轻松提取数据进行报告。顺便说一句,管理员不会在管理面板中看到调查回复。

Firstly I think this question can be related to any language, but I specified what I was using.

Excuse me if I start to bore also, but I am trying to find out the best way to build a dynamic survey management system.
My client basically has said to me that the data has to be stored in MS SQL as his client has only got MS SQL connector for SAS, which is going to do reporting.

My logic so far is this:
1st. Setup the survey itself, i.e. ask for title, quick overview, etc, etc.
2nd. Define your questions.
3rd. Publish survey.

Now what I have done so far is that when they "publish survey", I have created a dedicated database table for this survey which will house the responses.
From the admin side of this, they will not be able to modify the questions, maybe the question title but that is about it. They cant add/remove questions.

Question is, is creating individual database tables a good thing? My only worry really is that say the admin creates like 30 questions, I will have 30 columns in that dedicated table. To go with that, this way might be easy for the SAS system to pull in data for reporting. The administrator will not see the survey responses in the admin panel btw.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

暗喜 2024-10-19 16:30:45

我在语言等级考试中做过类似的事情。我选择了更灵活的方法,如下表。

+------+    +-------------+    +-------------+    +-------------+    +----------+
| Exam |    | Question    |    | Choice      |    | Answer      |    | User     |
+------+    +-------------+    +-------------+    +-------------+    +----------+
| id   |    | id          |    | id          |    | id          |    | id       |
| name |    | questionNb  |    | choice      |    | user_id     |    | name     |
+------+    | question    |    | question_id |    | exam_id     |    | email    |
            | exam_id     |    | isAnswer    |    | question_id |    | password |
            +-------------+    +-------------+    | choice_id   |    +----------+
                                                  | isGood      | 
                                                  +-------------+ 

这个模型让我可以轻松地进行 15 个问题的考试、30 个问题的考试和 50 个问题的考试。要使这个模型适应调查,您可能只需要删除 isAnswer 和 isGood 部分,您应该很好,并用年龄、收入、性别等匿名一般数据替换用户数据。

I have done something similar for a language grading exam. I opted for a more flexible approach with the following tables

+------+    +-------------+    +-------------+    +-------------+    +----------+
| Exam |    | Question    |    | Choice      |    | Answer      |    | User     |
+------+    +-------------+    +-------------+    +-------------+    +----------+
| id   |    | id          |    | id          |    | id          |    | id       |
| name |    | questionNb  |    | choice      |    | user_id     |    | name     |
+------+    | question    |    | question_id |    | exam_id     |    | email    |
            | exam_id     |    | isAnswer    |    | question_id |    | password |
            +-------------+    +-------------+    | choice_id   |    +----------+
                                                  | isGood      | 
                                                  +-------------+ 

This model allowed me to easilly have a 15 questions exam, a 30 questions exam and a 50 questions exam. To adapt this model for survey, you might just have to remove the isAnswer and isGood part and you should be good and replace users data with anonymous general data like age, income, sex.

向日葵 2024-10-19 16:30:45

为每个问题创建一个列是完全错误的,在运行时出于面向业务的目的更改数据库是“永远不会做的”。
阅读有关“关系数据库”的内容应该如下所示:

table_surveys
ID
Survey_name

表_问题
ID
fk_survey(table_surveys 的外键)
问题文本
(问题值?也许)

table_questions_options
ID
Question_id(table_questions的外键)
option_value(对于测试,这可以是 true/false,对于调查,可以是数值)
选项标签

表用户
ID
用户名
经过
名称

表_答案
ID
options_fk(table_question_options 的外键)
users_fk(table_users 的外键)

这样所有内容都链接在一起(不会重复使用选项、问题或不同调查中的内容)

Creating a column for each question is totally wrong, altering the database at runtime for business oriented purpose is a "never ever do".
Read something about "relational databases" things should look like this:

table_surveys
id
survey_name

table_questions
id
fk_survey (foreign key to table_surveys)
question_text
(question value? maybe)

table_questions_options
id
question_id(foreign key to table_questions)
option_value (this can be true/false for a test or a numeric value for a survey)
option_label

table_users
id
username
pass
name

table_answers
id
options_fk (foreign key to table_question_options)
users_fk (foreign key to table_users)

This way everything is linked together (No reusing of options,or questions or stuff into different surveys)

浮光之海 2024-10-19 16:30:45

根据文档中的注释,PHP 中的 MS SQL 支持 是不确定的充其量。 PHP 是您可以在该项目中使用的唯一语言吗?如果没有,您可能需要考虑使用 C#、VB.Net 或与 SQL Server 更兼容的语言。否则,您可以首先将数据存储在 MySQL 中,然后在需要进行分析时将其导出到 MS SQL Server。

According to the comments in the documentation, MS SQL Support in PHP is iffy at best. Is PHP the only language you are allowed to use for the project? If not, you might want to consider using C#, VB.Net or something more compatible with SQL Server. Otherwise, you could initially store the data in MySQL, and export it to MS SQL Server when you needed to do analysis.

夜司空 2024-10-19 16:30:45

不知道我是否真的理解你的问题。但我曾经搭建过这样一个调查系统。其结果非常快速且简单,涉及以下表格(如果我没记错的话):

USER, SURVEYS, QUESTIONS, ANSWERS, [some mapping tables]

SAS 将从虚拟任何表中获取数据。如果所有内容都集中在一张或两张桌子上,那就更容易了。

Dont know, if I really understand your question. But I once built such a survey system. And it came out pretty quick and easy with about the following tables (if I remember right):

USER, SURVEYS, QUESTIONS, ANSWERS, [some mapping tables]

The SAS will fetch the data from virtual any table. If everything in one or two tables, it will even be easier.

年华零落成诗 2024-10-19 16:30:45

恕我直言,Kibbee 对 PHP/MSSQL 的支持实际上非常好。我们经常这样做,并且性能优于 PHP/MySQL,并且与编译的 C#/MSSQL 相匹配(在我们非常有限且不科学的测试中)。这是假设您在 Win 计算机上运行 PHP。使用 TLS 连接器运行 PHP 到单独的 MSSQL 框是另一个问题,并且配置起来可能很痛苦。

无论如何,我们有一个类似的场景,并使用一个表来管理表单(带有 FormID 的表单作为主表),另一个表来管理字段/问题(带有 FieldID 的字段、FieldType,例如 Y/N、文本、选择等)。 ),另一个将字段“分配”到表单(FormFields w/ FormFieldID、FormID、FieldID、选择项数组中的参数等)。然后是另一组表格来处理问题的回答。

我同意小组其他成员的观点。确保标准化并且不要为每个问题创建单独的列。最初会需要更多工作,但是当您只需向表中添加几行而不是重新编写查询和重新设计表时,您会很高兴。

With all due respect to Kibbee, PHP/MSSQL support is actually VERY good. We do it quite often, and the performance bests PHP/MySQL and matches compiled C#/MSSQL (in our very limited and unscientific testing). This is assuming you're running PHP on a Win machine. Running PHP with a TLS connector to a separate MSSQL box is another ball of wax and can be a pain to configure.

Anyway, we had a similar scenario and went with one table to manage forms (Forms w/ FormID as the primary), another to manage fields/questions (Fields w/FieldID, FieldType such as Y/N, text, select, etc.), and another to "assign" a field to a form (FormFields w/ FormFieldID, FormID, FieldID, parameters in an array for select items, etc.). Then yet another set of tables to deal with the answering of the questions.

I agree with the rest of the group. Make sure to normalize and don't create a separate column for each question. It'll be more work initially, but you'll appreciate it when you simply have to add a few rows to a table instead of re-writing your queries and re-designing your tables.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文