Hello,
I want to display Students results of each student all subject marks should be in one row wise format.
My Controller is:
public function marksall() {
$class_id = $this->input->post('class_id');
$exam_id = $this->input->post('exam_id');
$this->data['subjects'] = $this->mark->get_subject_list_all($exam_id, $class_id, $section_id);
$this->data['subjectnames'] = $this->mark->get_subject_names_by_exam($exam_id, $class_id, $section_id);
$this->layout->view('mark_sheet/marksall', $this->data);
}
Model is:
public function get_subject_list_all($exam_id, $class_id, $section_id)
{
$this->db->select('M.*,S.name AS subject, G.point, G.name');
$this->db->from('marks AS M');
$this->db->distinct('S.name');
$this->db->join('subjects AS S', 'S.id = M.subject_id', 'left');
$this->db->join('grades AS G', 'G.id = M.grade_id', 'left');
$this->db->where('M.academic_year_id', $this->academic_year_id);
$this->db->where('M.class_id', $class_id);
$this->db->where('M.section_id', $section_id);
$this->db->where('M.exam_id', $exam_id);
return $this->db->get()->result();
}
My Output is:
Subject total obtain
sub1 100 80
sub1 100 74
sub2 150 125
sub2 150 108
sub3 75 45
sub3 75 63
And I want the result like below:
Sub1 sub2 sub3
total obtain total obtain total obtain
100 80 150 125 75 45
100 74 150 108 75 63
Please help I dont have any idea that how to do this?
What I have tried:
<table>
<tr>
<!--
<?php if (isset($subjectnames) && !empty($subjectnames)) {
foreach ($subjectnames as $sub) { ?>
<th colspan="2"><?php echo $sub->subject . " Marks ".$sub->exam_total_mark; ?></th>
<?php } } ?>
</tr>
if (isset($subjects) && !empty($subjects)) {
?>
<tr>
<?php
foreach ($subjectnames as $sub) { ?>
<td>
<?php
foreach ($subjects as $obj) {
?>
<table>
<?php while($obj->subject == $sub->subject) { ?>
<tr>
<td><?php echo $obj->exam_total_mark; ?></td>
<td><?php echo $obj->obtain_total_mark; ?></td>
</tr>
<?php } ?>
</table>
<?php } ?>
</td>
<?php } ?>
</tr>
<?php } ?>
</table>