在MySQL数据库表中存储多个字符串 [英] Storing more than one string in a MySQL Database Table
问题描述
在问我的问题之前,我只想感谢昨天回答了我的问题的所有人 - > 使用javascript进行倒计时。
创意: 我使用php创建了一个测验,但我想创建一个MySQL数据库,并有一个包含所有问题,答案和多项选择的表格。
问题:
由于测验是多项选择,知道如何去存储表中的多项选择选项。我可以存储这些选项,并让每个答案用一个特殊字符分开,并让PHP获取字符串并分开选项吗?
例如:问题:你最喜欢的颜色是什么?选项:蓝色=红色=紫色=黄色(数据库视图)
你认为什么是这样的最佳做法? b
我认为最好的做法是使用多个表。一个是问题,一个是答案。 answer
表将包含 question_id
以及一个标志,无论它是否是正确答案
它可能看起来像这样
TABLE问题
字段:id,text
TABLE answer
FIELDS:id,question_id,text,correct
对所有答案使用一个字段的问题是,您可能会意外地使用您用于分隔答案文本内的字符。
Before I ask my question, I just wanted to thank everyone that replied to my question yesterday -> Countdown using javascript.
Idea:
I created a quiz using php, but I would like to create a MySQL Database and having a table with all the questions, answers and multiple choice stored inside.
Issue:
Since the quiz is multiple choice, I don't know how to go about storing the multiple choice options in the table. Could I store the options and have each answer separated by a special character and let php get the string and separate the options?
Ex: Question: What is your favorite color? Options: Blue=Red=Purple=Yellow.(Database View)
What do you folks think is the best practice for something like this?
I think the best practice would be to use multiple tables. One for the question and one for answers. The answer
table would contain question_id
as well as a flag whether or not it is the correct answer
It could look like this
TABLE questions
FIELDS: id, text
TABLE answers
FIELDS: id, question_id, text, correct
The problem with using one field for all the answers is that you could accidently use the character you use for splitting inside the text of an answer
这篇关于在MySQL数据库表中存储多个字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!