Codeigniter:在将数据作为列的总和提取时遇到问题

时间:2018-03-09 02:31:36

标签: codeigniter select count fetch

我是Codeigniter的新手,我有两个名为Users and Amount的表,一个用户的Amount Table中有多个金额具有相同的user_id,这是外键。如果user_id相同,我想获取数据并总结金额值。

我的模态是:

public function client_list(){
$this->db->select_sum('*', sum('amount'));
$this->db->from('users');
$this->db->join('amount', 'amount.user_id = users.ID');
$query=$this->db->get();
$result=$query->result();
return $result;
} 

控制器是:

public function index(){
$data['records'] = $this->Admin_model->client_list();
    $this->load->view('admin/Client_list', $data);
}

查看部分是:

<?php
     foreach($records as $record):
?>

<tr class="odd gradeX">
 <td>
  <label class="mt-checkbox mt-checkbox-single mt-checkbox-outline">
  <input type="checkbox" class="checkboxes" value="1" />
  <span></span>
  </label>
 </td>
 <td> <?php echo $record->firstname;  ?> </td>
 <td> <?php  echo $record->lastname; ?> </td>
 <td> <?php  echo $record->phone;?> </td>
 <td> <?php  echo $record->email;?> </td>
 <td> <?php  echo $record->amount;?> </td>
 <td> <?php echo $record->dateofbirth;?> </td>
</tr>
<?php   endforeach;  ?> 

亲切的帮助将受到高度赞赏。

0 个答案:

没有答案