I want to do an automatic type pagination of Facebook, which when it reaches the bottom of the page it automatically loads another page with more posts. I've already researched the subject and found nothing that could really help me to the point where I can.
The code I use to list posts is this:
<?php
$post = $pdo->query("SELECT * FROM postagens")->fetchAll();
if(!$post){
print_r($pdo->errorInfo());
}
foreach ($post as $posts){
?>
I tried to do what @abfurlan said and by the way I did something wrong.
The page index.php
looks like this:
<?php require_once"../conexao.php"?>
<style>
#conteudo{
width:100px; background:#CCC;
height:200px;
overflow-y:auto;
}
</style>
<script src="JS/jquery.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function() {
$("#conteudo").scroll(function() {
if ($(this).scrollTop() + $(this).height() == $(this).get(0).scrollHeight) {
//requisição ajax para selecionar postagens
$.ajax({
url:'postagens.php', //Página PHP que seleciona postagens
type:'POST', // método post, GET ...
data: 'limit=5&offset=0', //seus paramêtros
success: function(data){ // sucesso de retorno executar função
$('#conteudo').append(data); // adiciona o resultado na div #conteudo
} // fim success
}); // fim ajax
} // fim do if
}); // fim scroll
}); // fim document ready
</script>
<div id="conteudo">
</div>
And the postagens.php
page looks like this:
<?php require_once "../conexao.php" ?>
<?php
$post = $pdo->query("SELECT * FROM postagens LIMIT 5 OFFSET 0")->fetchAll();
if(!$post){
print_r($pdo->errorInfo());
}
foreach ($post as $posts){
?>
<?php echo $posts['ID']; echo "<br>"?>
<?php } ?>
Nothing is happening ...