I’m having difficulty iterating through records while scrolling window. My initial thought was to load enough records to fit on screen then load an additional set when window scrolled to bottom. I’ve tried using session / variables to pass some counter to a function, no luck. The code below returns enough records to fit window height but with 0,10 limit. What would be a simple method to resolve this?
Another question is should I use LIMIT or ID > + LIMIT on the Mysql query?
$(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/>';
}
?>
to call the php file multiple times sound bad,
all that overhead proberly worse then getting all at once.
can’t you just calculate how many you need, and ask for that number?
i also think you should add an order by, to be sure the result always gets in the same order.