From 8fb5251aa1cbaf872e953c2125e0316220196c33 Mon Sep 17 00:00:00 2001 From: Indieteq Date: Mon, 9 Sep 2013 20:43:43 +0200 Subject: Added aggregate functions Added Aggregate methods such as : min, max, avg, sum etc --- easyCRUD/easyCRUD.class.php | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/easyCRUD/easyCRUD.class.php b/easyCRUD/easyCRUD.class.php index d6e6bff..5e21bbe 100644 --- a/easyCRUD/easyCRUD.class.php +++ b/easyCRUD/easyCRUD.class.php @@ -99,5 +99,31 @@ class Crud { public function all(){ return $this->db->query("SELECT * FROM " . $this->table); } + + public function min($field) { + if($field) + return $this->db->single("SELECT min(" . $field . ")" . " FROM " . $this->table); + } + + public function max($field) { + if($field) + return $this->db->single("SELECT max(" . $field . ")" . " FROM " . $this->table); + } + + public function avg($field) { + if($field) + return $this->db->single("SELECT avg(" . $field . ")" . " FROM " . $this->table); + } + + public function sum($field) { + if($field) + return $this->db->single("SELECT sum(" . $field . ")" . " FROM " . $this->table); + } + + public function count($field) { + if($field) + return $this->db->single("SELECT count(" . $field . ")" . " FROM " . $this->table); + } + } -?> \ No newline at end of file +?> -- cgit v1.1