- Seme Framework
- version 4.0.3
- Requirements
- Download & Install
- Configuration
- Tutorials
- URI Routing
- Constants
- Global Variables
- Model
- View
- Controller
- cdn_url
- config
- constructor
- getAdditional
- getAdditionalBefore
- getAdditionalAfter
- getAuthor
- getCanonical
- getContentLanguage
- getDescription
- getIcon
- getJsContent
- getJsFooter
- getJsReady
- getKey
- getKeyword
- getLang
- getRobots
- getShortcutIcon
- getThemeElement
- getTitle
- input
- lib
- load
- loadCss
- loadLayout
- putThemeContent
- putJsContent
- putJsFooter
- putJsReady
- render
- resetThemeContent
- session
- setAuthor
- setCanonical
- setContentLanguage
- setDescription
- setIcon
- setKey
- setKeyword
- setLang
- setShortcutIcon
- setTheme
- setTitle
- Library
- CLI (command line interface)
- Core
- Issue
- Deployment
Limit Method
The limit method is part of Query Builder for limiting query result by executing LIMIT [A],[B] SQL command.
This method also suitable for creating pagination with datatables pagination.
Basic Usage
Here is the basic usage limit method from $db property on SENE_Model class.
$this->db->limit(int $offset, int $count): $this->dbParameters
This method has 2 required parameters.
$offset
The $offset value can be zero or positive integer for specifying the offset of the first row to be returned.
$count
The $count value can be zero or positive integer for specifying the maximum number of rows to be returned.
Example
On this example will show limiting the result query by using limit method in a model class.
<?php
class D_Blog_Model extends SENE_Model{
public $table = 'd_blog';
public $table_alias = 'b';
public function __construct(){
parent::__construct();
}
public function latest(){
$this->db->select("*");
$this->db->from($this->table,$this->table_alias);
$this->db->order_by("date_create","desc");
$this->db->limit(0,5);
return $this->db->get();
}
public function latest3ExceptTheFirst(){
$this->db->select("*");
$this->db->from($this->table,$this->table_alias);
$this->db->order_by("date_create","desc");
$this->db->limit(1,4);
return $this->db->get();
}
}SQL Result
The following is the SQL command that generated from D_Blog_Model model methods.
-- result from executing D_Blog_Model::latest() --
SELECT *
FROM `d_blog` b
ORDER BY `date_create` DESC
LIMIT 0, 5;
-- result from executing D_Blog_Model::latest3ExceptTheFirst() --
SELECT *
FROM `d_blog` b
ORDER BY `date_create` DESC
LIMIT 1, 4;