CodeIgniter Forums
Quiz Questions output - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: Quiz Questions output (/showthread.php?tid=66375)



Quiz Questions output - cndunga - 10-17-2016

Dear All,

I have a code which is displaying questions in a quiz randomly. I would like the questions to be displayed as entered in the database. What do I need to change?


RE: Quiz Questions output - drusnac19 - 10-17-2016

Your activity domain :/


RE: Quiz Questions output - cndunga - 10-18-2016

The code for retrieving the questions is as follows

//GET EXAM QUESTION DETAILS (for the Quiz/Exam)
$quizRecords = $this->base_model->run_query(
"select q.*,qq.*,s.subjectid,s.name as subjectname from "
.$this->db->dbprefix('quiz')." q, ".$this->db->dbprefix('quizquestions')
." qq, ".$this->db->dbprefix('subjects')." s 
where qq.quizid=q.quizid and qq.subjectid=s.subjectid and q.quizid=".$id
);
$questArray = array();
foreach ($quizRecords as $r) {
$subjectwiseQuestions = $this->base_model->run_query(
"select * from ".$this->db->dbprefix('questions')
." where subjectid=".$r->subjectid." and difficultylevel='"
.$r->difficultylevel."' and answer1!='' and answer2!='' 
and correctanswer!='' ORDER by rand() LIMIT ".$r->totalquestion
);
array_push($questArray, $subjectwiseQuestions);
}
$this->data['quiz_info'] = $quizRecords;

if ($this->session->userdata('isExamStarted') == 1) {
$this->session->set_userdata('questions', $questArray);
$answers = '';
foreach ($this->session->userdata('questions') as $row) {
foreach ($row as $q) {
$answers[$q->questionid] = $q->correctanswer;
}
}