相同id的Codeigniter sum列



大家好,我正在尝试将数据插入我的数据库。有些值包含相同的id。我想在插入期间求和,而不是添加新行:

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']));
}

在进入查询之前,您应该在数组中对相同的id值求和,然后将数据传递到您的查询中。检查此链接到

对具有相同密钥的数组求和

相关内容

  • 没有找到相关文章

最新更新