CodeIgniter MySQL 选择和查询

问题描述 投票:0回答:1

我在 CodeIgniter 中使用下面的模型来获取列的总和:

public function b2c_totalsales()
    {
        $this->db->select_sum('total_price');
        $result=$this->db->from('orders_b2c');
        return $result;
    }

在控制器中:

$data['total_sales']=$this->reports_b2c->b2c_totalsales(); 

我得到:

严重性:4096

消息:类 CI_DB_mysqli_driver 的对象无法转换为字符串

文件名:views/reports_b2c.php

错误在哪里?

php select activerecord sum codeigniter-3
1个回答
3
投票

您需要使用

get
:

执行查询
$this->db->select_sum('total_price');
$result = $this->db->get('orders_b2c')->row();
return $result;
© www.soinside.com 2019 - 2024. All rights reserved.