I have a working function in my model where I'm trying to get the position of students in a class-based
on their subject scores.
The problem is that the where clause isn't filtering results to classify them based on subjects.
please help me solve this
model:
PHP Code:
public function GetSubjectPosScores($exam_group_class_batch_exam_subject_id)
{
$this->db->order_by('get_tot_score', 'DESC');
$this->db->select('get_tot_score');
$this->db->where('exam_group_class_batch_exam_subject_id', $exam_group_class_batch_exam_subject_id);
return $this->db->get('exam_group_exam_results')->result();
}
controller:
PHP Code:
public function GetSubjectPosScores($exam_group_class_batch_exam_subject_id)
{
$data = $this->examresult_model->GetSubjectPosScores($exam_group_class_batch_exam_subject_id);
return $data;
}
view:
PHP Code:
<td style="border: 1px solid black; font-size:15px;font-weight:bold;width:40px;text-align:center;color:black;"> <?php
$scores2 = $CI->GetSubjectPosScores($exam_result_value->exam_group_class_batch_exam_subject_id); //echo $value->pos;
$scores = array_column($scores2, 'get_tot_score');
$pos = array_search($exam_result_value->get_tot_score, $scores);
$number = $pos + 1;
echo $CI->ordinal($number);
?></td>
thank you.