Categories

Wednesday, October 2, 2024
#919814419350 therichposts@gmail.com
Laravel

Laravel pagination using mysql limit offset

Laravel 7.2 routing with route group auth guard check with prefix

Laravel pagination using mysql limit offset

Hello to all, welcome to therichpost.com. In this post, i will tell you, Laravel pagination using mysql limit offset.

Laravel is the top mvc framework in php.

Here is working and tested code for Laravel pagination using mysql limit offset:
// Paginate
$limit = 2;

//$_GET['page'] - get page number form url like - www.therichpost.com?page=1

$offset = (null !== $_GET['page']) ? ($_GET['page'] == 1) ? 0 : ($_GET['page']-1) * $limit : 0;

$raw_sql = 'SELECT * FROM user';

//get total number of pages divided by limit
$total_pages = sizeof(DB::select(DB::raw($raw_sql))) / $limit;

$query = 'SELECT * FROM user LIMIT '.$limit.' OFFSET '.$offset;

$user = DB::select(DB::raw($query));

 

 If you have any query related to this post, then feel free to ask. the rich post

 

therichpost
the authortherichpost
Hello to all. Welcome to therichpost.com. Myself Ajay Malhotra and I am freelance full stack developer. I love coding. I know WordPress, Core php, Angularjs, Angular 14, Angular 15, Angular 16, Angular 17, Bootstrap 5, Nodejs, Laravel, Codeigniter, Shopify, Squarespace, jQuery, Google Map Api, Vuejs, Reactjs, Big commerce etc.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.