I am creating an exam report in php using codeigniter and postgresql which displays the questions and the number of students who correctly answered the questions and the number of students who answered the questions incorrectly. When I tried displaying the data, it only prints one row when in fact I have 3 rows. I used print_r() to know what are the elements of my array and it looks like this: RESULT: print_r()
But then when I tried displaying it in views, it turns out like this: Result of displaying in View
I have these in my controller:
public function loadViewExamResult(){
$this->load->model('exam_model');
$exam_no= $this->uri->segment(3);
$data['answers'] = $this->exam_model->correctWrong($exam_no);
print_r($data['answers']) ;
$this->load->view('exam_report_chart',$data);
}
Model:
<?php
foreach ($answers as $row) {
$question = $row->question;
$correct = $row->correct;
$wrong = $row->wrong;
}
?>
<div class="row">
<div class="col-lg-12">
<section class="panel">
<header class="panel-heading">
EXAM STATISTICS
</header>
<div class="panel-body text-center">
<table class="table table-striped table-advance table-hover">
<tbody>
<tr>
<th>QUESTION</th>
<th>No. of Correct</th>
<th>No. of Wrong</th>
</tr>
<tr>
<td><?php echo $question;?></td>
<td><?php echo $correct;?></td>
td><?php echo $wrong;?></td>
</tr>
</tbody>
</table>
</div>
</section>
</div>
</div>
How do I solve this?