I'm new to CodeIgniter and PHP in general and I'm stuck in displaying data from a query.
This is my query which I believe is correct.
$sql = $this->db->query("SELECT sum( ".$totField.") FROM ".$table." s WHERE class_id='".$class."' AND subject_id='".$subject."' AND section_id=".$section." GROUP BY `subject_id`");
This query is basically getting to sum of all the total scores of students in different subjects. I'm going to be displaying these scores in a table in the view and am at a loss. I know I should place codes in the student_model, student.php controller, and studentview. I'm kind of confused. This is what I'm doing and I'm very sure I'm wrong.
I need your help. Thanks
This is the view:
<td style="border: 1px solid black;font-size:12px;width:5px;white-space: nowrap;"></td>
<td style="border: 1px solid black;font-size:12px;width:30px;text-align:left;"><?php echo $subName['subject_name'];?></td>
<td style="border: 1px solid black;font-size:12px;width:30px;text-align:center;">
<?php
$sumMarks = $this->db->query("SELECT sum( ".$totField.") FROM ".$table." s WHERE class_id='".$class."' AND subject_id='".$subject."' AND section_id=".$section." GROUP BY `subject_id`");
echo $sumMarks;?>
</td>
MODEL
public function SubjectTotal($subject_id,$class_id,$section_id,$session_id,$table,$totField)
{
$this->db->select_sum($totField);
$this->db->where('subject_id', $subject_id);
$this->db->where('class_id', $class_id);
$this->db->where('section_id', $section_id);
$this->db->where('session_id', $session_id);
$this->db->group_by('subject_id');
return $this->db->get($totField)->row();
}
CONTROLLER
public function SubjectTotal($subject_id,$class_id,$section_id,$session_id,$table,$totField)
{
$data = $this->student_model->SubjectTotal($subject_id,$class_id,$section_id,$session_id,$table,$totField);
return $data->$totField;
}
How do I echo this?