CodeIgniter Forums
Get position (rank) based on subject score - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: Get position (rank) based on subject score (/showthread.php?tid=82487)



Get position (rank) based on subject score - EseMiami - 07-15-2022

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. 



RE: Get position (rank) based on subject score - InsiteFX - 07-16-2022

Move your order_by below your where order_by should be the last statement before retrieving the record with get.