Categories

See More
Popular Forum

MBA (4887) B.Tech (1769) Engineering (1486) Class 12 (1030) Study Abroad (1004) Computer Science and Engineering (988) Business Management Studies (865) BBA (846) Diploma (746) CAT (651) B.Com (648) B.Sc (643) JEE Mains (618) Mechanical Engineering (574) Exam (525) India (462) Career (452) All Time Q&A (439) Mass Communication (427) BCA (417) Science (384) Computers & IT (Non-Engg) (383) Medicine & Health Sciences (381) Hotel Management (373) Civil Engineering (353) MCA (349) Tuteehub Top Questions (348) Distance (340) Colleges in India (334)
See More
( 6 months ago )

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

General Tech Learning Aids/Tools
Max. 2000 characters
Replies

usr_profile.png
Naveen Shastri

User

( 6 months ago )

Your data tables are awful. You need one table for questions and another table for answers. Each entry in the answers table refers back to a question in the 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.

usr_profile.png
Shiv Thapa

User

( 6 months 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>O</abbr>)?
            [answers] => Array
                (
                    [0] => Array
                        (
                            [correct] => 1
                            [answer] => 60<abbr title="Pounds per square inch">PSI</abbr>.
                        )
                    [1] => Array
                        (
                            [correct] => 0
                            [answer] => 45<abbr title="Pounds per square inch">PSI</abbr>.
                        )
                    [2] => Array
                        (
                            [correct] => 0
                            [answer] => 30<abbr title="Pounds per square inch">PSI</
			
        

what's your interest