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].

This method suitable for creating pagination with datatable method.

Parameters

Limit 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 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

Model::order_by Model::get