/** * Return the sum of a specific field for the current query * * @param mixed $Field */ public final function sum($Field) { //If there is data existing, return the sum of that if (sizeof($this->all()) > 0) { $Result = 0; foreach ($this->all() as $Row) { $Result += $Row->{$Field}; } return $Result; } else { $this->db->select_sum($Field); $Query = $this->db->get($this->_table()); $Row = $Query->row(); return $Row->{$Field}; } }