Initially when my view loads, it should display the first question and answer. When press the next button I need to pass next value to the model and get the second question and answer, and if next button is clicked again it should display the third question and answer. The next button should be clickable until the last question appears. I have the following code:
Model
function getNextQuestions($quizID,$qusNo) {
$check = "SELECT * FROM question WHERE quiz_id = '$quizID' AND id='$qusNo'";
$query = $this->db->query($check);
if ($query->num_rows() > 0) {
return $query->result();
} else {
return NULL;
}
}
Controller
public function index()
{
$this->load->model('Model_questions');
$quizId = $_POST['quizID_click'];
$data['questions'] = $this->Model_questions->getNextQuestions($quizId,"1");
$this->load->view('question_view', $data);
}
public function displayNextQuestions()
{
$this->load->model('Model_questions');
$qusId = $_POST['question_nextClick'];
$data['questions'] = $this->Model_questions->getNextQuestions($quizId,$qusId);
$this->load->view('question_view', $data);
}
View
<div id="body">
<?php
echo $questions[0]->question . "<br>"
. $questions[0]->choice1 . "<br>"
. $questions[0]->answer. "<br>";
echo '<form action="/Test/index.php/question_controller/displayNextQuestions" method="POST">
<input type="submit" value="Next">
<input type="hidden" name="question_nextClick" value="2" />
</form>';
?>
I didn't get the output that i need, what are the modifications that i should do. Please help me.