到目前为止,我如何才能从数据库中减去数据库中foreach循环中提取的数据的两个总和,以使用codeigniter显示在数据表中。
function fetch_user(){
$fetch_data = $this->point_m->make_datatables();
$data = array();
foreach ($fetch_data as $row)
{
$sub_array = array();
$sub_array[] = $row->idnumber;
$sub_array[] = $row->firstname;
$sub_array[] = $row->middlename;
$sub_array[] = $row->lastname;
$sub_array[] = $row->course_id;
$sub_array[] = $row->schoolyear;
$sub_array[] = $row->semester;
$sub_array[] = $row->point;
$sub_array[] = $row->redeem;
$data[] = $sub_array;
}
$output = array(
"draw" => $_POST['draw'],
"recordsTotal" => $this->point_m->get_all_data(),
"recordsFiltered" => $this->point_m->get_filtered_data(),
"data" => $data
);
echo json_encode($output);
}
$ row-> point和$ row-> redeem已被求和,现在我想知道是否可以减去这两个($ row-> point,$ row-> redeem)以及方法。
这是我的查询
$query = $this->db
->select("students.id,idnumber, firstname, middlename, lastname, course_id, schoolyear, semester, sum(point) as 'point', sum(redeem) as 'redeem'")
->distinct()
->from('students')
->join('section_student', 'students.id = section_student.student_id', 'LEFT')
->group_by('idnumber, firstname, middlename, lastname, course_id, schoolyear, semester')
->where('schoolyear','schoolyear')
->where('semester','semester');
$query = $this->db->get();
return $query->result();
答案 0 :(得分:0)
我只是添加另一个sub_array并减去这两个
$sub_array[] = $row->point - $row->redeem;