Skip to content

Instantly share code, notes, and snippets.

@SeunMatt
Created November 7, 2018 10:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SeunMatt/df9d88822bead128251862bdd31098ab to your computer and use it in GitHub Desktop.
Save SeunMatt/df9d88822bead128251862bdd31098ab to your computer and use it in GitHub Desktop.
SQL SERVER-SIDE PAGINATION
==========================
```php
$realOffset = 0;
if(!is_null($limit) && $offset > 0) {
$realOffset = $offset * $limit;
}
if($offset < 0) {
$realOffset = 0;
}
if(!is_null($limit))
$CI->db->limit($limit, $realOffset);
```
SERVER-SIDE PAGINATION LOGIC FOR ELASTIC SEARCH
===============================================
```
if(page > 1)
realOffset = (page * limit) - limit;
- limit is the same as size or total number of records per page that I want
- page is the page number e.g. 1,2,3,4...
- realOffset is the actual value to pass to the search API as the from key
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment