Welcome Guest, Not a member yet? Register   Sign In
Displaying Question with multiple answers
#1

[eluser]code_has_been_ignited[/eluser]
hey,

Something just is not coming to me and I hope someone can provide some assistance to my issue.

I am trying to load a question and then display multiple answers for that question. My issue is I cannot seem to load more then 1 question and answer set. This is what my code looks like in my model:

Code:
public function getQuestions($quiz_id)
{
$query  = $this->db->query('SELECT * FROM '.$this->quiz_questions.' WHERE question_for = '.$quiz_id.'');
return $query;
}
public function getAnswers($quest_id)
{return $this->db->query('SELECT * FROM '.$this->quiz_answers.' WHERE question_id = '.$quest_id.'');
}

My View Has:
Code:
foreach ($question->result() as $questionw) {
  echo $questionw->question;
  }
foreach ($answers->result() as $row) {
        echo "<input type=\"radio\"  name=\"choice\" value=\"".$row->refrence."\"/>" . $row->answer . "";
}

I am trying to keep tight with the MVC pattern and I am relatively new to codeigniter and any hints and tips would be great.

Thanks You
#2

[eluser]Learn CodeIgniter[/eluser]
The row and row_array only return a single record.

The result and result_array return multiple records.

You can also use, to see what your query looks like.
Code:
echo $this->db->last_query();
#3

[eluser]code_has_been_ignited[/eluser]
My query looks good, But how do i loop through the results to display the question and its answers?

Thanks




Theme © iAndrew 2016 - Forum software by © MyBB