Facebook Style Auto Scroll Pagination using jQuery and PHP
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.
Screen Shots
Click on a photo below to scroll through the screen shots of the application!
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.
