Group By Method

Group By method is part of database class builder for selecting column data into a table.

Parameters

Group By method has 1 required parameters that is column name and value, another parameters are optional. Here is the completed parameters can be used by where methods

$this->db->group_by(string $condition): dbObject

$condition

Condition can be single column name or can be SQL Function.

Example usage

Here is the examples using group_by method. See the first of this page for full example.

Basic Usage

For example we assumed want to add new data in blog table. First, in the model:

class Blog_Model extends SENE_Model{
  var $tbl = 'blog';
  var $tbl_as = 'b';
  public function __construct(){
	 parent::__construct();
  }
  public function countByCategory(){
    $this->db->select_as("COUNT(*)",'total',0);
    $this->db->select_as("category",'category',0);
    $this->db->from($this->tbl,$this->tbl_as);
    $this->db->group_by("category");
    return $this->db->get();
  }
}

at the controller, we assumed has file named blog.php

class Blog extends Sene_Controller{
  public function __construct(){
    parent::__construct();
    $this->load('blog_model','bm'); #class scope model
  }
  public function index(){
    $blogs = $this->bm->countByCategory();
    $this->debug($blogs);
  }
}