Load the data While Scroll Down | Sanwebcorner

Load the data While Scroll Down

Load the data While Scroll Down:

Load Data or Contents While Scrolling Page Down with Jquery, Now a days you can see many web sites loading page data as user scroll down. This is very easy and useful trick to load images as user scroll using jquery.

load the data while scroll down
load the data while scroll down




Loading Database records automatically when user scrolls down to the bottom of the page. This technique can be seen in Twitter, facebook, and several other websites.

In this scroll down script i am using php and mysql, Jquery.

Database file:

Database Name : tse

Table structure: 

CREATE TABLE IF NOT EXISTS `messages` (
`mes_id` int(11) NOT NULL,
  `msg` varchar(250) DEFAULT NULL
) ENGINE=InnoDB  DEFAULT CHARSET=utf8 AUTO_INCREMENT=119 ;

load_data.php:

<?php
include('config.php');
$last_msg_id=$_GET['last_msg_id'];
$action=$_GET['action'];
if($action <> "get")
{
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Load Data while scrolling san web tutorials</title>
<link rel="stylesheet" href="san.css" type="text/css" />
<script type="text/javascript" src="jquery-1.2.6.pack.js"></script>
<script type="text/javascript">
$(document).ready(function(){
function last_msg_funtion() 
    var ID=$(".message_box:last").attr("id");
$('div#last_msg_loader').html('<img src="bigLoader.gif">');
$.post("load_data.php?action=get&last_msg_id="+ID,
function(data){
if (data != "") {
$(".message_box:last").after(data);
}
$('div#last_msg_loader').empty();
});
};  
$(window).scroll(function(){
if  ($(window).scrollTop() == $(document).height() - $(window).height()){
  last_msg_funtion();
}
}); 
});
</script>
</head>
<body>
<div align="center">
<div>
<h2><a href="http://sanwebtutorials.blogspot.in/">sanwebtutorials.blogspot.in</a></h2>
</div>
<?php
include('load_first.php');
?>
<div id="last_msg_loader"></div>
</div>
</body>
</html>

<?php
}
else
{
include('load_second.php');
}
?>

config.php:

<?php
$mysql_hostname = "localhost";
$mysql_user = "root";
$mysql_password = "";
$mysql_database = "tse";
$prefix = "";
$bd = mysql_connect($mysql_hostname, $mysql_user, $mysql_password) or die("Could not connect database");
mysql_select_db($mysql_database, $bd) or die("Could not select database");
?>

load_fist.php:

<?php
$sql=mysql_query("SELECT * FROM messages ORDER BY mes_id DESC LIMIT 10");
while($row=mysql_fetch_array($sql))
{
$msgID= $row['mes_id'];
$msg= $row['msg'];
?>
<div id="<?php echo $msgID; ?>"  align="left" class="message_box" style="margin-top:25px;" >
<?php echo $msg;  ?> 
</div>
<?php
}
?>

load_second.php:

<?php
$last_msg_id=$_GET['last_msg_id'];
 $sql=mysql_query("SELECT * FROM messages WHERE mes_id < '$last_msg_id' ORDER BY mes_id DESC LIMIT 5");
 $last_msg_id="";
while($row=mysql_fetch_array($sql))
{
$msgID= $row['mes_id'];
$msg= $row['msg'];
?>
<div id="<?php echo $msgID; ?>"  align="left" class="message_box"  style="margin-top:25px;">
<?php echo $msg; ?> 
</div>
<?php
}
?>



Post a Comment

Labels

360 degree view product image 3d rotate 3d text 3step-form Accordion menu ajax All Browsers Animated Background Gradient animation audio controller auto complete Best accordion menu bootstrap border bounce effect on hover Breadcrumb calculate age by dob calendar Captcha change image on mouse move color chooser countdown Counter on scroll Css css animation css buttons css hover css3 customized upload Button Date picker delete data from table Different scroll speed email otp verification email verifier Embed eventlist Expanding Menu feedbck form flash news section close button full screen menu Google custom search Google Maps Google reCAPTCHA Google site search gradient hide menu Horizontal News ticker Hover Htm Html html dropdown html form html5 html5 form validation Iframe image hover increment decrement textbox value based on select box Javascript Jquery js Layered image effect on mouse hover lock & unlock page scroll marquee marquee with close button mobile number validation mobile otp login Multi-level-drop-down-menu multi-level-form Multi-Step-form mysql News ticker on hover change text to image our team page password strength checker Photoshop PHP populate html selectbox Popup image on click the link pure css Question type form Random password Redirect page Based on the select box while submit the form responsive responsive menu responsive popup box Responsive Vertical Time line design rotate image selectbox based on select box simple coming soon page simple countdown based on end date simple typing effect slider sliding tab sms otp login statistic counter on scroll switch tag shape team member Time picker toggle toggle view transparent button underline animation up down slide validation vertical fixed sidebar Webtips Youtube