Randomizing -and remembering that randomisation- multiple choice questions in php

General Tech Learning Aids/Tools 2 years ago

0 2 0 0 0 tuteeHUB earn credit +10 pts

5 Star Rating 1 Rating

Posted on 16 Aug 2022, this text provides information on Learning Aids/Tools related to General Tech. Please note that while accuracy is prioritized, the data presented might not be entirely correct or up-to-date. This information is offered for general knowledge and informational purposes only, and should not be considered as a substitute for professional advice.

Take Quiz To Earn Credits!

Turn Your Knowledge into Earnings.

tuteehub_quiz

Answers (2)

Post Answer
profilepic.png
manpreet Tuteehub forum best answer Best Answer 2 years ago

 

Problem:

I'm trying to code a multiple choice quiz for my fellow students -and primarily to aid my own learning- and so I'm creating a multiple choice web-based quiz using PHP (5.2.08) and MySQL (5.0.32)

The questions table is:

+----------+--------------+------+-----+---------+----------------+
| Field    | Type         | Null | Key | Default | Extra          |
+----------+--------------+------+-----+---------+----------------+
| id       | int(6)       | NO   | PRI | NULL    | auto_increment | 
| question | varchar(200) | NO   |     | NULL    |                | 
| correct  | varchar(80)  | NO   |     | NULL    |                | 
| wrong1   | varchar(80)  | NO   |     | NULL    |                | 
| wrong2   | varchar(80)  | NO   |     | NULL    |                | 
| wrong3   | varchar(80)  | NO   |     | NULL    |                | 
+----------+--------------+------+-----+---------+----------------+

Sample print_r($questions) output for one question:

Array
(
    [0] => Array
        (
            [id] => 1
            [question] => What is the correct pipeline pressure for Nitrous Oxide (<abbr title="Nitrous Oxide.">N<span class="chem-notation">2</span>Oabbr>)?
            [answers] => Array
                (
                    [0] => Array
                        (
                            [correct] => 1
                            [answer] => 60<abbr title="Pounds per square inch">PSIabbr>.
                        )
                    [1] => Array
                        (
                            [correct] => 0
                            [answer] => 45<abbr title="Pounds per square inch">PSIabbr>.
                        )
                    [2] => Array
                        (
                            [correct] => 0
                            [answer] => 30<abbr title="Pounds per square inch">PSI
                                                
                                                
0 views
0 shares
profilepic.png
manpreet 2 years ago

Your data tables are awful. You need one table for questions">questions and another table for answers. Each entry in the answers table refers back to a question in the questions">questions table and has a flag indicating whether it is the correct answer.

So, the QUESTIONS table has the following fields:

  • QUESTION_ID
  • QUESTION_TEXT
  • QUESTION_TYPE -- Like MC, TF, FIB ...

The ANSWERS table has the following fields:

  • ANSWER_ID
  • QUESTION_ID
  • ANSWER_TEXT
  • IS_CORRECT

Makes your life infinitely easier and obviates the raison d'etre for this question.


0 views   0 shares

No matter what stage you're at in your education or career, TuteeHub will help you reach the next level that you're aiming for. Simply,Choose a subject/topic and get started in self-paced practice sessions to improve your knowledge and scores.