我想获取像52,100这样的值,但它只返回52个mysql codeigniter

时间:2016-05-04 10:09:48

标签: mysql codeigniter

逗号由数据库中的值提取分隔

 public function get_data() 
     {  $this->db->select_sum("total_sale");
        $this->db->from('one_month_report');
        $query = $this->db->get();
        if ($query->num_rows() > 0) {
        return $query->result();
        } else {
        return FALSE;
       }
    }

来自评论的控制器

public function profit_in_last_month_view() {

$this->load->view('pages/header'); 

$data['listProduct'] = $this->mproduct->get_data(); 

$this->load->view('pages/profit_in_last_month', $data); 

echo $this->db->last_query();

exit; 

$this->load->view('pages/footer'); 

}

1 个答案:

答案 0 :(得分:0)

这应返回最近52000个结果的total_sale总和。

$this->mproduct->get_data(52000)


public function get_data($limit,$offset=0){
  $limit = ($limit) ? $limit : 20;

  $q = $this->db
            ->select_sum('total_sale')
            ->limit($limit, $offset)
            ->order_by('created_at', 'desc')
            ->get('one_month_report');

  return ($q->num_rows() > 0) ? $q->result() : null;
}