Posted inTechnology / Ajax / CSS / JavaScript / jQuery / Laravel / Mysql / Mysqli / php / Programming

Data auto Load While scrolling page down with jquery PHP and MySQL

Data auto Load While scrolling page down with jquery PHP and MySQL

In this Post We Will Explain About is Data auto Load While scrolling page down with jquery PHP and MySQL With Example and Demo.Welcome on Pakainfo.com – Examples, The best For Learn web development Tutorials,Demo with Example! Hi Dear Friends here u can know to Data Load While Page Scroll with jQuery PHP and MySQLExample

In this post we will show you Best way to implement load data dynamically on page scroll using jquery ajax and php, hear for Data auto Load While Page Scroll down with jQuery PHP and MySQLwith Download .we will give you demo,Source Code and examples for implement Step By Step Good Luck!.

File Structure List

Index.php
do_result_data.php
get_data_list.js

create a table structure

CREATE TABLE IF NOT EXISTS `postdata` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`comments` longtext NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;

Create Database Connection – db_connect.php

 Connect failed: %s\n", mysqli_connect_error());
	exit();
}
?>

Include External Libs






index.php

Example: Simple Data Load While Page Scroll steps with jQuery PHP and MySQL Devloped By Pakainfo.com

Data auto Load While scrolling page down with jquery PHP and MySQL

get_data_list.js

$(document).ready(function(){
	$(window).scroll(function(){
	if ($(window).scrollTop() == $(document).height() - $(window).height()){
		if($(".total_nopage:last").val() <= $(".get_total_rec").val()) {
			var nopage = parseInt($(".total_nopage:last").val()) + 1;
			loadRecord('do_result_data.php?get_page='+nopage);
			}
		}
	});
});
function loadRecord(url) {
	$.ajax({
		url: url,
		type: "GET",
		data: {get_total_rec:$("#get_total_rec").val()},
		beforeSend: function(){
			$('#id_loader').show();
		},
		complete: function(){
			$('#id_loader').hide();
		},
		success: function(data){
			$("#results").append(data);
		},
		error: function(){}
	});
}

do_result_data.php

<?php
include_once("db_connect.php");
$perPage = 3;
$sql_query = "SELECT id, comments FROM postdata";
$get_page = 1;
	if(!empty($_GET["get_page"])) {
	$get_page = $_GET["get_page"];
	}
$first = ($get_page-1)*$perPage;
	if($first < 0) $first = 0;
	$query = $sql_query . " limit " . $first . "," . $perPage;
	$query_results = mysqli_query($dbcon, $query) or die("database error:". mysqli_error($dbcon));
	$records = mysqli_fetch_assoc($query_results);
	if(empty($_GET["get_total_rec"])) {
	$_GET["get_total_rec"] = mysqli_num_rows($query_results);
	}
$msgdis = '';
	if(!empty($records)) {
		$msgdis .= '';
		$msgdis .= '';
			while( $rows = mysqli_fetch_assoc($query_results) ) {
			$msgdis .= '
' .$rows["comments"] . '
'; } } echo $msgdis; ?>

Example

I hope you have Got What is load data while scrolling page down with jquery and php And how it works.I would Like to have FeadBack From My Blog(Pakainfo.com) readers.Your Valuable FeadBack,Any Question,or any Comments abaout This Article(Pakainfo.com) Are Most Always Welcome.

I am Jaydeep Gondaliya , a software engineer, the founder and the person running Pakainfo. I'm a full-stack developer, entrepreneur and owner of Pakainfo.com. I live in India and I love to write tutorials and tips that can help to other artisan, a Passionate Blogger, who love to share the informative content on PHP, JavaScript, jQuery, Laravel, CodeIgniter, VueJS, AngularJS and Bootstrap from the early stage.

Leave a Reply

Your email address will not be published. Required fields are marked *

We accept paid guest Posting on our Site : Guest Post Chat with Us On Skype