Loading.......
Loading...

Facebook Style Auto Scroll Pagination using jQuery and PHP

Posted on 25th October, 2025
PHP LOAD DATA AJAX AUTO LOAD AJAX PHP LOAD MORE FACEBOOK STYLE AJAX LOADER
This tutorial teaches you how to design a system with a pagination that loads and gets new items or contents automatically from the database just as Facebook does and displays on the screen to the user as the user scrolls the page down using Ajax, Jquery and PHP.

In the past, i gave several tutorials on pagination where you have to click on a button to load more data or content from a database and this process requires the effort of a user before more contents or data can be loaded from a database and its also time consuming.

As a result of this, i decided to come up with another similar tutorial where you do not have to click on a button to load more contents from a database. All you need to do is to scroll down to read the contents on the page while more contents are loaded and displayed on the page.

One major feature of this application is that, it does not work with the ID of each content loaded from the database as it is in the case of our previous tutorials but counts the number of items which have been loaded from the database and then use this number to check for the remaining contents which are left in the database for the next contents to be loaded. Am sure you understand what am talking about.

This application comes with a plugin which has been designed for you to just set things the way you want.
For instance, you can set the total number of items you want the script to load at each down-step, you can set the position you want the loading process to start from, you can set the script to load manually or automatically depending on what you prefer, you can set your desired label for "Loading Status", you can set your desired label for "Finished Contents in the database" and much more.

DATABASE CONNECTION SCRIPT

<?php
/**
 * These are the database connection details
 */  
 
define("HOST", 'localhost');     // The host you want to connect to.
define("USER", 'root');    		// The database username. 
define("PASSWORD", '');    		// The database password. 
define("DATABASE", 'demo');    	// The database name.

$mysqli = mysqli_connect(HOST, USER, PASSWORD) or die("Unable to connect to MySQL Server: ". mysqli_connect_error());
mysqli_select_db($mysqli, DATABASE) or die("Unable to connect to Database: ". DATABASE);
?>


PHP CODE THE DOES THE LOADING FROM THE DATABASE

<?php
include "config.php";

$vpb_start = isset($_POST['vpb_start']) && is_numeric($_POST['vpb_start']) ? strip_tags($_POST['vpb_start']) : 'vpb_is_finished';
$vpb_total =  isset($_POST['vpb_total']) && is_numeric($_POST['vpb_total']) ? strip_tags($_POST['vpb_total']) : 'vpb_is_finished';

if($_POST['page'] && !empty($_POST['page']))
{
	if($_POST['page'] == "laod-more-post")
	{
		if( $vpb_start == "vpb_is_finished" || $vpb_total == "vpb_is_finished" )
		{
			echo "vpb_is_finished";
		}
		else {
			$check_data = mysqli_query($mysqli,"select * from `pagination_posts` order by `id` asc limit ".$vpb_total." offset ".$vpb_start);
			
			if(mysqli_num_rows($check_data) > 0)
			{
				while($row = mysqli_fetch_array($check_data))
				{
					$content = strip_tags($row['message']);
					echo '<div class="auto_load_box">
					<h2>'.$row['name'].'</h2>';
					echo '<p>'.$content.'...</p>
					</div>';
				}
			}
			else
			{
				echo "vpb_is_finished";
			}
		}
	}
	else
	{
		echo 'vpb_loading_error';
	}
}
?>


HOW TO CALL THE JS FUNCTION THAT DOES THE AUTO-LOAD OF CONTENTS FROM THE DB

<script type="text/javascript">
$(document).ready(function() 
{
	$('#loaded_data').vasplus_post_scroller({

		vpb_total_per_load  : 10, // Total number of posts per scroll to be loaded on the page
		vpb_start           : 0, // Default - loading start at 0 offset
		vpb_no_more         : 'No more posts', // This is the message shown to the user when the post is finished
		vpb_load_more       : 'Load more posts', // This is the message shown to the user when set auto scroll to false to load more data    
		vpb_delay           : 600, // Wait after this time when a user scrolls down to start again
		vpb_auto_load       : true, // Set to true for auto scroll and set to false to scroll manually
		vpb_page_identifier : 'laod-more-post', // Not really necessary unless you need it otherwise leave it alone
		vpb_url             : 'laod-more-post.php', // This is the URL to the page that gets content from the database
		vpb_loading_div_id  : 'vpb_loading_box' // This is the ID of the div where the loaded contents will be displayed
		
	});
});
</script>

This is a very simple to understand application as all you need to do are well explained in the script.

The script is very easy to understand and customize with programming code comments to ease usability.

To install the system on your server, simply download the zipped folder containing the required files, extract it to your system, open a file named README.txt then follow the three installation steps given in that file.

To see the system in action, please click on the demo button below and download the script if you like what you see.
Post Comment
Press Enter to send
No comment yet.

Submit your Job or Project Today!

We can help you turn your idea into reality, take over your existing project, or extend your current development team.

Submit your idea job or project below and we will follow up with you shortly.

OUR OBJECTIVE

Our objective is to reach a place where our services will be highly regarded by businesses from various industrial domains for building their innovative busines solutions with our cutting-edge technological expertise, interactive designs and uncompromised quality.

OUR MISSION

We aspire to help businesses ranging from startups to enterprises, who reach out to us with their requirements, in achieving great lengths, expanding their reach, upscaling their products, and generate a large user-base with our outstanding and cost-effective services.

Please Wait....
Please Wait...