Welcome Guest, Not a member yet? Register   Sign In
How do I get the total amount from a column?
#1

Hi,

I'm upgrading my CI3 model to CI4, but things are not working well.

CI 3
PHP Code:
// Sales
 
$this->db->select_sum('total');
 
$result $this->x_model->get('order', array('created_on BETWEEN DATE_SUB(NOW(), INTERVAL 7 DAY) AND NOW()' => null));
 
$data['sales_count'] = $result->total

CI 4
PHP Code:
  public function total_weekly_sales()
    {
        return $this->db->table('order')
        ->selectSum('total')
        ->where("created_on BETWEEN DATE_SUB(NOW(), INTERVAL 7 DAY) AND NOW()")
        ->get();
    
It doesn't work. It gives me
Code:
Object of class CodeIgniter\Database\MySQLi\Result could not be converted to string.
Any idea where am I doing wrong?
Reply


Messages In This Thread
How do I get the total amount from a column? - by castle - 01-31-2022, 05:28 AM



Theme © iAndrew 2016 - Forum software by © MyBB