I’m storing values (int) for quantities in my database. I need to run a count on the total quantity by adding all the row totals together. The problem with $this->db->count_all_results() is that it returns the total rows but doesn’t count all the values stored. Any help would be much appreciated.
function currentDealTotalQuantity($id)
{
$this->db->select('quantity');
$this->db->from('table');
$this->db->where('id', $id);
$total_sold = $this->db->count_all_results();
if ($total_sold > 0)
{
return $total_sold;
}
return NULL;
}
1 Answer