Infinite scroll pagination using codeigniter jquery and ajax

Infinite scroll pagination using codeigniter jquery and ajax

In this tutorial, we are going to learn how to create infinite scroll pagination using Codeigniter jquery and ajax. we have seen on Facebook, Twitter or other websites on that automatically loaded content when scrolling down to the web page.

So you can follow the below steps and see our example for mouse scroll pagination in Codeigniter.

Overview

Create a Database and Table

Connect to Database

Get the limit data

Get the infinite data

Create a Database and Table

First of all for we will create a database and table. after then we will add dummy data in the table. here we take the products table and also added products related data into the product table. so you can see the below code.

Connect to Database

Here in this step, we will open database.php file in the config directory and some changes in this file like as hostname, database username, database password, and database name.

Get the limit data

Here in this step, we have to need limited data for display data. so we are displaying 10 data per rows. for that, we will take a constant variable so we can display 10 data per rows. now here we will take two hidden inputs fields for the current row position and the total number of row

So you can see our index method code for the first time get rows records.

Get the infinite data

Here in this step, we have used some functions. you can see it.

$(window).scrollTop() function when scroll then it will return current vertical position.

$(document).height() function return height of the document.

$(window).height() function return pixel value of the height of the (browser) window.

When we scroll down if the current position and bottom position are the same then it will be passed next current row data using ajax and call into the pagination method. after it will be helpful for getting limit data into the query.

 

so you can see our full code.

views/product.php

controllers/Welcome.php

models/Product_model.php

We have suggested if you still do not read our article related article then you can read our article related article. How to create Pagination with PHP and MySql.

Please follow and like us: