SitePoint Sponsor |
|
User Tag List
Results 1 to 3 of 3
-
Jul 30, 2009, 22:03 #1
- Join Date
- Jul 2009
- Posts
- 1
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Quick question about creating a basic grading system... please help asap
So I am building a quick online testing system. I have it setup so I can create multiple choice questions (all questions have exactly 4 answers), save the questions, answers, and the correct answer in mysql db, and have it randomly show 25 questions form the database on the actual testing page. I am stuck on how to actually get the results of what they click on.
This is the code to show the questions on the test page.
Code:$result8 = mysql_query("SELECT * FROM sampletest ORDER BY RAND() LIMIT 25"); while($row8 = mysql_fetch_assoc($result8)) { echo "<table width='200' border='0' cellpadding='0' cellspacing='0'> <tr> <td><div align='center'>"; echo $row8['question']; echo "</div></td> </tr> <tr> <td> <p align='center'> <label> <select name='"; echo $row8['id']; echo "' size='5' id='"; echo $row8['id']; echo "'> <option value='"; echo $row8['a']; echo "'>"; echo $row8['a']; echo "</option> <option value='"; echo $row8['b']; echo "'>"; echo $row8['b']; echo "</option> <option value='"; echo $row8['c']; echo "'>"; echo $row8['c']; echo "</option> <option value='"; echo $row8['d']; echo "'>"; echo $row8['d']; echo "</option> </select> </label> <br /><hr> </p></td> </tr> </table>"; }
Any more info I can give and I will.
-
Jul 31, 2009, 07:50 #2
- Join Date
- May 2002
- Location
- RI-USA
- Posts
- 113
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
I think you'd have to create another table in the database with all the correct answers and the corresponding question id. Then on the final page do a lookup and see if they got it right or not.
Jim
-
Jul 31, 2009, 08:15 #3
- Join Date
- Jul 2008
- Posts
- 5,757
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
http://www.php.net/manual/en/faq.htm...aq.html.arrays
Code:<select name="questions[523]"> <option value="a">...</option> <option value="b">...</option> <option value="c">...</option> <option value="d">...</option> </select> <select name="questions[199]"> <option value="a">...</option> <option value="b">...</option> <option value="c">...</option> <option value="d">...</option> </select>
PHP Code:// print_r($_POST['questions']);
$question_ids = implode(',', array_map('intval', array_keys($_POST['questions'])));
$sql = "
SELECT question_id
, answer_code
FROM questions
WHERE question_id IN ($question_ids)
";
PHP Code:while ($row = mysql_fetch_assoc($res)) {
if ($row['answer_code'] === $_POST[$row['question_id']]) {
//correct
} else {
// wrong
}
}
Bookmarks