Welcome Guest, Not a member yet? Register   Sign In
Problem with sum result
#1

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:

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


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

View
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')
$this->selectSum('
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!
Reply




Theme © iAndrew 2016 - Forum software by © MyBB