Limit Method

Limit method digunakan untuk membatasi jumlah baris dari hasil query.

Limit method ini cocok untuk diaplikasikan dengan DataTable.

Dengan fungsi ini memungkinkan untuk mengatur banyaknya jumlah data dan akan tampil pada halaman ke berapa.

Metode ini akan menghasilkan query seperti ini:

SELECT * FROM table WHERE 1 LIMIT [A],[B]

Parameter

Limit method membutuhkan 2 parameter yaitu offset dan 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 limit method. See the first of this page for full example.

Basic Usage

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

<?php
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();
  }
}

page method v.s. limit method

Page method used for limiting by page and page size

Limit method used for limiting data by MySQL traditional limit method