Database
A database needs to be created to store the information about questions, options and correct answers. So let's create a database using the following query. Here is a table 'questions' that contains all the quiz questions.
CREATE TABLE IF NOT EXISTS `questions` ( `qid` int(11) NOT NULL AUTO_INCREMENT, `question` varchar(150) NOT NULL, `is_enabled` int(11) NOT NULL, PRIMARY KEY (`qid`) ) ENGINE=MyISAM AUTO_INCREMENT=5 DEFAULT CHARSET=latin1;
INSERT INTO `questions` (`qid`, `question`, `is_enabled`) VALUES (1, 'Which function is used to reverse the order of elements in an array?', 1), (2, 'Which function is used to return character from the ASCII value?', 1), (3, 'Which function is used to check the existence of a constant?', 1), (4, 'Which function is used to return the last element of an array?', 1);
Here is a table 'quiz_options' that contains all the quiz options -
CREATE TABLE IF NOT EXISTS `quiz_options` ( `option_id` int(11) NOT NULL AUTO_INCREMENT, `qid` int(11) NOT NULL, `option` varchar(150) NOT NULL, `is_enabled` int(11) NOT NULL, PRIMARY KEY (`option_id`) ) ENGINE=MyISAM AUTO_INCREMENT=17 DEFAULT CHARSET=latin1;
INSERT INTO `quiz_options` (`option_id`, `qid`, `option`, `is_enabled`) VALUES (1, 1, 'array_rev()', 1), (2, 1, 'array_reverse()', 1), (3, 1, 'reverse()', 1), (4, 1, 'array_end()', 1), (5, 2, 'chr()', 1), (6, 2, 'ascii()', 1), (7, 2, 'asc()', 1), (8, 2, 'return_chr()', 1), (9, 3, 'define()', 1), (10, 3, 'const()', 1), (11, 3, 'defined()', 1), (12, 3, 'exist()', 1), (13, 4, 'end()', 1), (14, 4, 'arr_end()', 1), (15, 4, 'last()', 1), (16, 4, 'end()', 1);
At last, we create a table 'quiz_answer' for storing the correct answer of the quiz -
CREATE TABLE IF NOT EXISTS `quiz_answer` ( `qa_id` int(11) NOT NULL AUTO_INCREMENT, `qid` int(11) NOT NULL, `option_number` int(11) NOT NULL, PRIMARY KEY (`qa_id`) ) ENGINE=MyISAM AUTO_INCREMENT=5 DEFAULT CHARSET=latin1;
INSERT INTO `quiz_answer` (`qa_id`, `qid`, `option_number`) VALUES (1, 1, 2), (2, 2, 1), (3, 3, 3), (4, 4, 4);