hey i would like some help with javascript, autoload function, like (infinty scroll)
what i have done is: called the database to get all data (SELECT * FROM ... LIMIT 50 OFFSET ...)
now i need to know how to increase the offset number when they scroll down to the end of the
i really tried finding this on google, but only things i get are not suitable for me, javascript is my worst scripting language
i hope someone can help me with this ! or show me a really good tutorial :) thx for reading
this is how I did it a long time ago:
JS:
var times = 1;
$(window).scroll(function() {
if($(window).scrollTop() + $(window).height() == $(document).height() && $('#endless').is(":visible") && searching != true) {
times++;
$.ajax({
type: 'post',
url: "classes/infinite.php",
data: {length: times},
complete: function(response) {
document.getElementById('endless').innerHTML = document.getElementById('endless').innerHTML + response.responseText;
}
});
}
});
classes/infinite.php file:
$length = $_POST['length'];
$length = $length * 12;
$pdo = new PDO("mysql:host=localhost;dbname=market", "root", "");
$sth = $pdo->prepare("SELECT * FROM `offers` WHERE amount > 0 ORDER BY `date` LIMIT :lim1 , :lim2");
$length2 = $length - 12;
$sth->bindParam(':lim1', $length2, PDO::PARAM_INT);
$sth->bindParam(':lim2', $length, PDO::PARAM_INT);
I used ajax to post the limits to my databquery file and then I appended the result to the endless div.
Hope this helps