将数据按排列顺序存入mysql [英] Storing data, in arranged sequence into mysql

查看:24
本文介绍了将数据按排列顺序存入mysql的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我向学生 & 随机提问使用他的会话 ID 将他的答案存储到 mysql &比以同样的方式提取.我在提问时在查询中使用了 Order By RAND() 函数

I asked random question to student & stored his answers using his session id into mysql & than extracted the same way. I used Order By RAND() function in my query while asking the question

$query = "SELECT * FROM question ORDER BY RAND() LIMIT 0,1";

但现在我想以排列的顺序存储答案,我可以使用 Q_ID 但我不想向用户显示 q_id.那么如何将 q_id 存储到另一个表中而不将其显示给用户.其次,我也想向我的学生展示正确的答案.

But Now I Want to Store answers in an arranged sequence for such purpose i can use Q_ID but i don't want to show q_id to user. So how can i store q_id into another table without showing it to user. Secondly i want to show correct answers to my students too.

但我真的不知道如何解决这些问题:(

but i really don't know how to tackle these thing :(

用于存储答案的查询

$order= "INSERT INTO radio (Option1,Option2,Option3,user) VALUES ('".$Option['Option1']."','".$Option['Option2']."','".$Option['Option3']."','".session_id()."')";

查询从mysql中提取数据

Query For Extracting Data From mysql

$qry=mysql_query("SELECT * FROM radio where user='".session_id()."'", $con);

推荐答案

如果没有您的实际数据库架构/更多信息,就很难为您提供最佳建议.

Without your actual database schema/more information it is difficult to give you the best advice possible.

向表格收音机添加一个字段,使其看起来像这样:

Add a field to the table radio so that it looks something like this:

RADIO (*user*, *questionId*, Option1, Option2, Option3)

(由于堆栈溢出,格式化星号代表主键)

(due to stack overflow formatting stars represent the primary key(s))

其中 questionID 是引用 QUESTION(id) 的外键.如果您的问题表中没有 id 字段,也请添加该字段.

where questionID is a foreign key that references QUESTION(id). If you don't have an id field in your question table add that too.

然后当您向用户显示问题时,将问题 ID 保存为标签内的隐藏输入字段,如下所示:

Then when you display the question to the user, save the question ID as a hidden input field inside the tag like so:

<input type='hidden' name='questionId' value='".$data['id']."' />

提交表单后,您的 $_POST 数组中的问题 ID 将位于 $_POST['questionId']

When the form is submitted you will have the question ID available in your $_POST array at $_POST['questionId']

然后您可以修改您的 INSERT 查询以插入问题 ID,并且在稍后显示数据时不显示它.

Then you can modify your INSERT query to insert the question ID as well and simply not display it when you display the data later.

--

至于向学生显示正确答案,您需要以某种方式将正确答案存储在表格中.一种方法是在问题表中添加一个字段,指示哪个选项是正确答案,即TINYINT(1) 将包含 1、2 或 3,具体取决于哪个答案是正确的.然后,您可以使用它来生成一个页面,其中包含问题的正确答案.

As for displaying the correct answers to the students, you will need to store the correct answer in your table somehow. One way would be to add a field to your question table indicating which of the options is the correct answer, I.E. a TINYINT(1) which will contain a 1, 2, or 3 depending on which answer is correct. You can then use that to generate a page with the correct answer to the question.

这篇关于将数据按排列顺序存入mysql的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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