我很难在滚动窗口时迭代通过记录。我最初的想法是加载足够的记录以适应屏幕,然后在窗口滚动到底部时加载另外一组记录。我试过使用会话/变量来传递一个计数器到一个函数,没有运气。下面的代码返回足够的记录来适应窗口高度,但是有0,10个限制。什么是解决这个问题的简单方法?一个简单的方法来无限滚动MySql拉
另一个问题是我应该在Mysql查询上使用LIMIT或ID> + LIMIT?
$(function(){
setInterval(function(){
var totalHeight, currentScroll, visibleHeight;
if (document.documentElement.scrollTop)
{ currentScroll = document.documentElement.scrollTop; }
else
{ currentScroll = document.body.scrollTop; }
totalHeight = document.body.offsetHeight;
visibleHeight = document.documentElement.clientHeight;
if (totalHeight <= currentScroll + visibleHeight)
{
$.get('infinite_pull.php', function(data) {
$('body').append(data);
//alert('Load was performed.');
});
}
else
{
$('.dd').css('background-color','white');
}
}
, 100);
});
PHP
<?php
session_start();
mysql_connect('localhost','root','');
mysql_select_db('project5');
$query = "select user_email from users limit 0,10;";
$results= mysql_query($query);
while($row = mysql_fetch_array($results)){
echo $row['0'] . '<br/>';
}
?>