title: Counting row totals with Codeigniter Active Record
body: <p>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.</p>
  
  <pre><code>function currentDealTotalQuantity($id)
  {
  
      $this-&gt;db-&gt;select('quantity');
  
      $this-&gt;db-&gt;from('table');
  
      $this-&gt;db-&gt;where('id', $id);
  
      $total_sold = $this-&gt;db-&gt;count_all_results();
  
      if ($total_sold &gt; 0)
      {
          return $total_sold;
      }
  
      return NULL;
  
  }
  </code></pre>