techansaari
techansaari

Reputation: 371

CodeIgniter MySQL select sum query

I am using model below in CodeIgniter to get the sum of a column:

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

and in the controller:

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

and I am getting:

Severity: 4096

Message: Object of class CI_DB_mysqli_driver could not be converted to string

Filename: views/reports_b2c.php

where is the error?

Upvotes: -1

Views: 749

Answers (1)

SteeveDroz
SteeveDroz

Reputation: 6156

You need to execute the query with get:

$this->db->select_sum('total_price');
$result = $this->db->get('orders_b2c')->row();
return $result;

Upvotes: 3

Related Questions