-1

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?

0

1 Answer 1

3

You need to execute the query with get:

$this->db->select_sum('total_price');
$result = $this->db->get('orders_b2c')->row();
return $result;
Sign up to request clarification or add additional context in comments.

2 Comments

No problem! Don't forget the ->row() to get one result or ->result() to get an array with all of them.
I see that people are still voting for my answer. Please try to migrate to CodeIgniter 4 if you can, as that new version adds a great deal of features, simplifies the syntax and makes CI4 a Framework that looks a bit more like the leaders of the market.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.