select_sum() public method

Generates a SELECT SUM(field) portion of a query
public select_sum ( $select = '', $alias = '' ) : object
return object
Beispiel #1
0
 /**
  * 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};
     }
 }