Limit Method

Limit Method is part of database class builder for limiting query result. It will produce same as SELECT * FROM table WHERE 1 LIMIT [A],[B].

Parameters

Update method has 2 required parameters that is offset and count.

$this->db->limit(int $offset, int $count): dbObject

$offset

Offset can be zero or positive integer for specifying the offset of the first row to be returned.

$count

Count can be zero or positive integer for specifying the maximum number of rows to be returned.

Example usage

Here is the examples using select 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 latest(){
    $this->db->select("*");
    $this->db->from($this->tbl,$this->tbl_as);
    $this->db->order_by("date_create","desc");
    $this->db->limit(0,5);
    return $this->db->get();
  }
  public function latest3ExceptOne(){
    $this->db->select("*");
    $this->db->from($this->tbl,$this->tbl_as);
    $this->db->order_by("date_create","desc");
    $this->db->limit(1,4);
    return $this->db->get();
  }
}