Welcome Guest, Not a member yet? Register   Sign In
Call to a member function row() on bool
#1

Please I have an issue where I try to repopulate fields in a section where I add scores for students in a class

In first term adding of scores, I used this function in my model and it worked perfectly. All scores fields were repopulated.

Code:
  public function get_student_mtscore($subjectId,$sessionId,$sectionId,$classId,$studentId){
  
         $sql = "SELECT mp.id, mp.student_id, mp.class_id, mp.section_id, mp.mt_ca1, mp.mt_ca2, mp.mt_ca3, mp.mt_ca4, mp.mt_ca5, mp.mt_ca6, mp.mt_project, mp.mt_affective, mp.mt_psychomotor, mp.mt_exam, mp.mt_tot_score, mp.created_at, mp.modified_at
                FROM mtscores_primary mp
                WHERE mp.class_id = ? AND mp.student_id = ? AND mp.section_id = ? AND mp.subject_id = ?  AND mp.session_id = ?
                UNION
                SELECT mt.id, mt.student_id, mt.class_id, mt.section_id, mt.mt_ca1, mt.mt_ca2, mt.mt_ca3, mt.mt_ca4, mt.mt_ca5, mt.mt_ca6, mt.mt_project, mt.affective, mt.mt_psychomotor, mt.mt_exam, mt.mt_tot_score, mt.created_at, mt.modified_at
                FROM mtscores_rn mt
                WHERE mt.class_id = ? AND mt.student_id = ? AND mt.section_id = ? AND mt.subject_id = ? AND mt.session_id = ?";
        $query = $this->db->query($sql, array($classId, $studentId, $sectionId, $subjectId, $sessionId, $classId, $studentId, $sectionId, $subjectId, $sessionId));
        $result = $query->row();
        return $result;
    }


While entering scores for students in second term, I used below code but I get an error code

An uncaught Exception was encountered
Type: Error
Message: Call to a member function row() on bool



Code:
public function get_student_ftscore($subjectId,$sessionId,$sectionId,$classId,$studentId){
  
         $sql = "SELECT mp.id, mp.student_id, mp.class_id, mp.section_id, mp.ft_ca1, mp.ft_ca2, mp.ft_ca3, mp.ft_ca4, mp.ft_ca5, mp.ft_ca6, mp.ft_project, mp.ft_affective, mp.ft_psychomotor, mp.ft_exam, mp.ft_tot_score, mp.created_at, mp.modified_at
                FROM ftscores_primary mp
                WHERE mp.class_id = ? AND mp.student_id = ? AND mp.section_id = ? AND mp.subject_id = ?  AND mp.session_id = ?
                UNION
                SELECT mt.id, mt.student_id, mt.class_id, mt.section_id, mt.ft_ca1, mt.ft_ca2, mt.ft_ca3, mt.ft_ca4, mt.ft_ca5, mt.ft_ca6, mt.ft_project, mt.affective, mt.ft_psychomotor, mt.ft_exam, mt.ft_tot_score, mt.created_at, mt.modified_at
                FROM ftscores_rn mt
                WHERE mt.class_id = ? AND mt.student_id = ? AND mt.section_id = ? AND mt.subject_id = ? AND mt.session_id = ?";
        $query = $this->db->query($sql, array($classId, $studentId, $sectionId, $subjectId, $sessionId, $classId, $studentId, $sectionId, $subjectId, $sessionId));
        $result = $query->row();
        return $result;
    }
 
This is the controller:

Code:
       public function GetClassStudentsForSubjectft()
    {
        $class_id = $this->input->post('class_id');

        $section_id = $this->input->post('section_id');
       
        $subject_id = $this->input->post('subject_id');
       
        $data['class_id'] = $class_id;

        $data['subject_id'] = $subject_id;

        $data['section_id'] = $section_id;

        $data['subjects'] = $this->subject_model->getAll();

        $class = $this->class_model->get();

        $data['classlist'] = $class;

        $data['session_name'] = $this->setting_model-> getCurrentSessionName();

        $session_id = $this->setting_model->getCurrentSession();

        $students = $this->student_model->GetClassStudentsForSubjectft($session_id, $class_id, $section_id);
       
        $data['students'] = [];
        if(!empty($subject_id)){
            foreach($students as $student){
                $ftscore = $this->ftprimary_model->get_student_ftscore($subject_id,$session_id,$section_id,$class_id,$student->student_id);
               
                $student->ftscores = $ftscore;
                $data['students'][] = $student;

            }
        }
       
//                        echo var_dump($data['students']);
//                die();

        $this->load->view('layout/header', $data);
        $this->load->view('admin/grades/subjectStudentsFT', $data);
        $this->load->view('layout/footer');
       
    }
 
please help me out.  Confused Confused Confused
Reply
#2

You have an error in your query. $query are now FALSE, and that's a boolean. So you need to check if it's not FALSE and then execute $query->row();
Reply




Theme © iAndrew 2016 - Forum software by © MyBB