Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
615 views
in Technique[技术] by (71.8m points)

php - Storing data, in arranged sequence into mysql

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";

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 :(

query for storing answers

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

Query For Extracting Data From mysql

$qry=mysql_query("SELECT * FROM radio where user='".session_id()."'", $con);
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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))

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.

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']."' />

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

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.

--

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...