如何为Infinite Scroll分页查询结果?

我有一个使用2个PHP文件和MySql数据库的示例页面,我正在尝试使用jQuery无限滚动。 如何从数据库加载下一组数据? 例如,我的图片数据库中有100条记录,我希望显示20条,然后在滚动后显示接下来的20条记录。

这是我目前的核心:

的index.php

 

images.html

      trata tata         

cos tam ....

<?php // Make a MySQL Connection mysql_connect("localhost", "root", "") or die(mysql_error()); mysql_select_db("test") or die(mysql_error()); // Retrieve all the data from the "test " table $result = mysql_query("SELECT * FROM foto") or die(mysql_error()); // store the records of the "TABLENAME" table into $row array and loop through while ( $row = mysql_fetch_array( $result, MYSQL_ASSOC ) ) { // Print out the contents of the entry //echo "details: ".$row['id']; echo '
'; echo "wwwwww"; echo '
'; } ?>
$(function(){ var $container = $('#container'); $container.imagesLoaded( function(){ $container.masonry({ itemSelector : '.box' }); }); });

您需要为查询添加LIMIT 。 MySQL手册中的示例:

 SELECT * FROM tbl LIMIT 5,10; # Retrieve rows 6-15 

这里, 5是起始偏移量, 10是要获取的行数。

对于客户端,您将需要无限滚动jQuery插件 。