如何用逗号将测验结果保存到数据库中
how to save quiz results into database with seaparated by comma
我有多项选择题测验脚本。每次登录后,用户每次测验可以回答10个问题。测试结束后,测试结果将保存到数据库中。结果存储如下:id
category_name
user_id
question_id
answer_id
time
1
php
nbsp nbsp nbsp nbsp nbsp nbsp nbsp nbsp nbsp;2
nbsp nbsp nbsp nbsp nbsp nbsp nbsp;1
nbsp nbsp nbsp nbsp nbsp nbsp nbsp nbsp nbsp 3
nbsp nbsp nbsp nbsp nbsp nbsp 40
2
nbsp;php
nbsp nbsp nbsp nbsp nbsp nbsp nbsp nbsp nbsp;2
nbsp nbsp nbsp nbsp nbsp nbsp nbsp;2
nbsp nbsp nbsp nbsp nbsp nbsp nbsp nbsp nbsp 3
nbsp nbsp nbsp nbsp nbsp nbsp 40
3
nbsp;php
nbsp nbsp nbsp nbsp nbsp nbsp nbsp nbsp nbsp;2
nbsp nbsp nbsp nbsp nbsp nbsp nbsp;3
nbsp nbsp nbsp nbsp nbsp nbsp nbsp nbsp nbsp 2
nbsp nbsp nbsp nbsp nbsp nbsp 40
我如何存储测试结果,比如这样:id
category_name
user_id
question_id
answer_id
time
1
php
nbsp nbsp nbsp nbsp nbsp nbsp nbsp nbsp nbsp;2
nbsp nbsp nbsp nbsp nbsp nbsp nbsp;1,2,3,4
nbsp nbsp;3,3,3,4
nbsp 30,25,45,43
nbsp nbsp nbsp;
在数据库中以这种方式存储数据是个坏主意,您应该重新考虑您的解决方案。在未来,基于这样的数据进行报告将非常困难。
但是,如果要在数据库中存储这种格式的数据,则需要序列化数据。在php中,您可以获取一个结果数组并对其进行序列化。这将把它更改为字符串,您可以将其保存在数据库中。
之后,您可以通过从数据库中提取字符串并在其上运行unserialize命令来取回数据
$data = array('1','2','3');
$serialized = serialize($data);
// $serialized will equal:
// a:3:{i:1;s:6:"elem 1";i:2;s:6:"elem 2";i:3;s:7:" elem 3";}
- 如何使用 Angular JS 将数据保存在数据库中
- PHP:显示sqlite数据库中的html格式数据,使用tinymce保存
- 将数据保存到数据库(ajax/php)后,使文本字段变灰/禁用
- 获取用户位置并将坐标保存在数据库中
- ForerunnerDB将其数据库保存在哪里
- 如何在本地存储(或其他数据库)上安全地保存敏感访问代码
- 输入框值将保存到 MySQL 数据库
- 如何从重定向的支付处理器网站提取交易详细信息并保存到我的rails 4数据库
- 将javascript变量保存到数据库中
- ASP.NET MVC-如何捕获多个复杂的ListBox值并将其保存到数据库中
- jTinder保存到数据库
- 验证数据并将其保存到数据库以供实时应用程序使用的正确方法
- Angular js,在选择元素上,我想 POST 数据以将其保存在数据库中,然后我想使用 PUT 更新它而无需重新加载
- HTML5数据库保存了详细信息以及一个按钮
- 如何确保在 Mocha 中的 done() 之前执行对数据库的循环保存
- 索引数据库保存范围为
- 将动态输入表单数据保存到数据库kendoui中
- 可以'编辑后不会将数据保存在数据库中,但网格显示更改
- 我如何在Asp.netmvc4中使用jquery-ajax创建文本框来保存数据库中的任何输入
- 在phonegap应用程序中保存数据库的位置