0

I am trying to update grades of student using update batch (multiple update)

However the problem arises when conditioning in the model, whereas the array condition does not accept else if statement

in this line, 'equiv' => $data['grade'][$i] == 65 ? 5 : 0, is there a way to make it a full condition statement where I can use else if and remove the else or :0 at the end of the line. The :0 makes all other data 0 which those data should not be affected.

public function updateAll(){
    $id = $this->input->post('studentID');

    $data = $this->input->post();
    
        for($i = 0; $i < (count($data['studentID'])); $i++){
        
            $batch[] = array(
            'studentID' => $data['studentID'][$i],
            'grade' => $data['grade'][$i],
            'equiv' => $data['grade'][$i] == 65 ? 5 : 0
            );

        }

    return $this->db->update_batch('tbl_college_grades', $batch, 'studentID');
}

1 Answer 1

2

THIS IS WORK FOR ME, GOOD LUCK

public function updateAll(){
    $id = $this->input->post('studentID');

    $data = $this->input->post();
    $selected_equiv;
    
        for($i = 0; $i < (count($data['studentID'])); $i++){
            data['grade'][$i] == 65 ? $selected_equiv = 5 : 0
            $batch[] = array(
            'studentID' => $data['studentID'][$i],
            'grade' => $data['grade'][$i],
            'equiv' => $selected_equiv
            );

        }

    return $this->db->update_batch('tbl_college_grades', $batch, 'studentID');
}
Sign up to request clarification or add additional context in comments.

1 Comment

Since when are we allowed to refer to a variable without the $ in PHP?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.