ActiveRecord + CodeIgniter - Return single value from query, not in array form ActiveRecord + CodeIgniter - Return single value from query, not in array form codeigniter codeigniter

ActiveRecord + CodeIgniter - Return single value from query, not in array form


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


$output = $this->db->query("YOUR QUERY")->row()->fieldname;

OR

$output = $this->db->get("TABLE NAME")->row()->fieldname;

Where fieldname is the name of the field you want the output of in your query.


this isn't the prettiest way. i can't find a way to do it with the active record api. but here's a one-liner to get it.

$result = array(    array('sum' => '23'));echo current( current( $result ) );