phpcodeignitersumquery-builderresultset

How to return the SUM() value of a SELECT query using CodeIgniter's query builder


Say you construct an active record query that will always just return a single value, how do you just access that single value instead of getting an array in return?

For instance, I am using query builder methods to return the SUM() of a single column. It will only return this one single SUM. Instead of having to parse the array, is there a way to assign the value as a function return equal to that value?


Solution

  • $query = $this->db->get(); // your ActiveRecord query that will return a col called 'sum'
    
    echo $query->row('sum');