CodeIgniter Forums
Problem with sum result - Printable Version

+- CodeIgniter Forums (
+-- Forum: CodeIgniter 4 (
+--- Forum: CodeIgniter 4 Support (
+--- Thread: Problem with sum result (/thread-77571.html)

Problem with sum result - achim_311 - 09-18-2020

How's it going everyone!!!

I want to perform a sum, multiple columns.  I have this code, i don't know if is the correct way to do it:

PHP Code:
public function getTotalOrders($customer_id){
    return $this->selectSum('total''s_h''ship_cost''total')
                      ->whereIn('status', ['DV''DVW'])
                      ->where('YEAR(order_date) = YEAR(CURDATE())')
                      ->total; (<-- i think here is the problem)

PHP Code:
data = [
     'totalorders' => $orders->getTotalOrders($customer_id),

PHP Code:
<?= $totalorders?>

The problem is that codeigniter (4) doesn't show me any errors, but the in the view doesn't show any result.
I've tried another way like ->first(); ->find() ->findAll() and with those it showed me error. 
Also i tried to add like this
PHP Code:
$this->selectSum('SUM(total) + SUM(s_h) + SUM(ship_cost) AS 'total')
total s_h ship_cost', 'total') 

But still the same error or result.
I hope you can give me a hand with this!
Thanks in advance!