Page Method

Page 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

Page method has 2 required parameters that is page and pagesize.

$this->db->page(int $page, int $pagesize): dbObject

$page

Page determine the current page of specified pagesize.

$pagesize

Pagesize the maximum result row count per page.

Example usage

Here is the examples using page 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:

<?php
class Blog_Model extends SENE_Model{
  var $tbl = 'blog';
  var $tbl_as = 'b';
  public function __construct(){
	 parent::__construct();
  }
  public function showFirstPagePer5Rows(){
    $this->db->select("*");
    $this->db->from($this->tbl,$this->tbl_as);
    $this->db->order_by("date_create","desc");
    $this->db->page(1,5);
    return $this->db->get();
  }
  public function showSecondPagePer10Rows(){
    $this->db->select("*");
    $this->db->from($this->tbl,$this->tbl_as);
    $this->db->order_by("date_create","desc");
    $this->db->limit(2,10);
    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