Hello guys I am trying to insert data into my database. Some values contain the same id. I want to sum during insertion and not add a new row:
 if ($q->num_rows() >0) 
 {
        $this->db->where('student_id',$id);
        $this->db->set('mark_obtained', ' mark_obtained+ '. $obtained_marks['mark_obtained'], FALSE);
        $this->db->update('position' , array('mark_obtained' => $obtained_marks , 'student_id' =>$row['student_id'] , 'exam_id'=> $row['exam_id'],'subject_id' =>$row['subject_id'],'section_id'=>$row['section_id'], 'class_id'=>$row['class_id']));
  } 
  else {
        $this->db->insert('position' , array('mark_obtained' => $obtained_marks , 'student_id' =>$row['student_id'] , 'exam_id'=> $row['exam_id'],'subject_id' =>$row['subject_id'],'section_id'=>$row['section_id'], 'class_id'=>$row['class_id']));
  }
 
     
    