How to paginate query results for Infinite Scroll?(如何为无限滚动的查询结果分页?)
问题描述
我有一个使用 2 个 PHP 文件和一个 MySql 数据库的示例页面,我正在尝试在其上使用 jQuery 无限滚动.如何从数据库加载下一组数据?例如,我的图片数据库中有 100 条记录,我想显示 20 条,然后滚动显示下 20 条.
I have a sample page that uses 2 PHP files and a MySql database, and I'm trying to use jQuery infinite scroll on it. How can I load the next group of data from database? For example, I have 100 records in my pictures database, and I want to show 20, and then the next 20 after some scrolling.
这是我目前的核心:
index.php
<?php
ob_start();
require_once('images.html');
ob_end_flush();
?>
images.html
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title> trata tata</title>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<!--[if lt IE 9]><script src="aHR0cDovL2h0bWw1c2hpbS5nb29nbGVjb2RlLmNvbS9zdm4vdHJ1bmsvaHRtbDUuanM="></script><![endif]-->
<link rel="stylesheet" href="./css/style.css" />
<!-- scripts at bottom of page -->
</head>
<body class="demos ">
<nav id="site-nav">
<h1><a href="./index.html">ole tu jest HOME</a></h1>
<h2>Menu 1</h2>
<ul class="docs-list">
<li><a href="../docs/intro.html">11111111</a>
</ul>
<h2>Menu 2</h2>
<ul class="demos-list">
<li><a href="../demos/basic-single-column.html">222222222</a>
<li class="current"><a href="#content">3333333333</a></li>
</ul>
</nav> <!-- #site-nav -->
<section id="content">
<h1>cos tam ....</h1>
<div id="container" class="clearfix">
<?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 '<div class="box photo col3">';
echo "<img src="Ii4kcm93Ww=="src']."" alt="d3d3d3d3" />";
echo '</div>';
}
?>
</div> <!-- #container -->
<script src="Li9qcy9qcXVlcnktMS43LjEubWluLmpz"></script>
<script src="Li9qcXVlcnkubWFzb25yeS5taW4uanM="></script>
<script>
$(function(){
var $container = $('#container');
$container.imagesLoaded( function(){
$container.masonry({
itemSelector : '.box'
});
});
});
</script>
<footer id="site-footer">
szaki <a href="http://desandro.com">sdfsdfdsfsdf</a>
</footer>
</section> <!-- #content -->
</body>
</html>
<!-- #container --><script src="Li9qcy9qcXVlcnktMS43LjEubWluLmpz"></script><script src="Li9qcXVlcnkubWFzb25yeS5taW4uanM="></script><脚本>$(函数(){var $container = $('#container');$container.imagesLoaded( 函数(){$container.masonry({itemSelector : '.box'});});});<footer id="site-footer">szaki <a href="http://desandro.com">sdfsdfdsfsdf</a></页脚></节><!-- #content -->
推荐答案
您需要将 LIMIT
添加到您的查询中.MySQL 手册中的示例:
SELECT * FROM tbl LIMIT 5,10; # Retrieve rows 6-15
Here, 5
is the starting offset, and 10
is the amount of rows you want to fetch.
这里,5
是起始偏移量,10
是您要获取的行数.
For the client-side you'll need the infinite scroll jQuery plugin.
这篇关于如何为无限滚动的查询结果分页?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何为无限滚动的查询结果分页?
- PHP foreach() 与数组中的数组? 2022-01-01
- 如何在 Symfony2 中正确使用 webSockets 2021-01-01
- openssl_digest vs hash vs hash_hmac?盐与盐的区别HMAC? 2022-01-01
- Oracle 即时客户端 DYLD_LIBRARY_PATH 错误 2022-01-01
- PHP - if 语句中的倒序 2021-01-01
- 使用 GD 和 libjpeg 支持编译 PHP 2022-01-01
- 覆盖 Magento 社区模块控制器的问题 2022-01-01
- 如何从数据库中获取数据以在 laravel 中查看页面? 2022-01-01
- Laravel 5:Model.php 中的 MassAssignmentException 2021-01-01
- 如何使用 Google API 在团队云端硬盘中创建文件夹? 2022-01-01