scroll infinito com ajax ! ajuda
estou com esse script de scroll infinito, ele mostra para min os 10 primeiros artigos , ate aqui ok , porem como eu faço para ele mostrar mais 10 artigos depois dos 10 primeiros ???
<?php include "conexao.php";?>
<!DOCTYPE html>
<html lang="pt-br">
<head>
<title>Sistema de busca igual facebook</title>
<meta charset="UTF-8" />
<link rel="stylesheet" type="text/css" href="css.css" />
<link rel="stylesheet" type="text/css" href="lib/css/default.css" />
<script src="lib/js/jquery.js" type="text/javascript"></script>
<script src="js-all.js" type="text/javascript"></script>
</head>
<body>
<h1>Infinite Scrolling, Demo 2</h1>
<ul id="posts">
<li>
<article>
<header>
<h1>This Is an Article</h1>
</header>
<?php include "load_first.php";?>
</article>
</li>
</ul>
<p id="loading">
<img src="images/loading.gif" alt="Loading…" />
</p>
</body>
</html>
<script type = "text/javascript">
$(document).ready(function() {
var win = $(window);
// Each time the user scrolls
win.scroll(function() {
// End of the document reached?
if ($(document).height() - win.height() == win.scrollTop()) {
$('#loading').show();
$.ajax({
url: 'load_second.php?id=<?php echo $id; ?>',dataType: 'html',
success: function(html) {
$('#posts').append(html);
$('#loading').hide();
}
});
}
});
});
</script>
load_first.php
<?php
include "conexao.php";
$mostraDados = mysqli_query($conecta, "SELECT * FROM artigo ORDER BY data DESC LIMIT 10")or die (mysqli_error());
while($linha = mysqli_fetch_array($mostraDados))
{
$id = $linha["id"];
$titulo = $linha["titulo"];
echo "
<p class='tm' id=$id > $id $titulo </p>";
}
?>
load_second.php
<?php
include "conexao.php";
$last_msg_id = $_GET ['id'];
$mostraDados = mysqli_query($conecta, "SELECT * FROM artigo WHERE id < '$last_msg_id' ORDER BY id DESC LIMIT 5")or die (mysqli_error());
$last_msg_id = " ";
while( $linha = mysqli_fetch_array($mostraDados))
{
$id = $linha["id"];
$titulo = $linha["titulo"];
$endereco = $linha["endereco"];
$cep = $linha["cep"];
?>
<div id = "<?php echo $id; ?>" class = "message_box" >
<?php echo $id; ?> <?php echo $titulo; ?>
</div>
<?php
}
?>Discussão (2)
Carregando comentários...