【发布时间】:2015-07-04 19:51:34
【问题描述】:
我为我的网站创建了一个画廊,我决定在我的画廊上使用jQuery infinite scroll 插件(例如:facebook 墙)。
所有数据均来自 PHP MyAdmin 数据库。我的问题是,如何让数据从数据库中无限滚动?我的所有代码都可以正常工作。
- 数据库:图库
- 表的表结构:posts
index.php:
<?php
include ("connect_database.php");
$select_post = "SELECT * FROM posts ORDER BY rand() LIMIT 5";
$run_posts = mysql_query($select_post);
while ($row=mysql_fetch_array($run_posts)) {
$post_id = $row['post_id'];
$post_date = $row['post_date']; //.etc here
?>
<div id="container">
<!-- gallery codes here and five thumbnails are randomly loading on homepage -->
</div>
<!--Next page for INFINITE SCROLL-->
<nav id="page-nav">
<a href="next-page.php"></a> <!--please check script.js-->
</nav>
当我在<nav> 标签中添加 html 或 php 文件时,下一页正在加载,没有任何问题。但是我需要为每个加载创建一个新的 php/html 文件。我有一个想法来加载接下来的 5 个缩略图而不创建一个新文件。我需要从数据库中获取下五个缩略图以无限滚动。
script.js:
var $container = $('#container');
$container.infinitescroll({
// infinite scroll options...
navSelector : "#page-nav",
// selector for the paged navigation (it will be hidden)
nextSelector : "#page-nav a:first",
// selector for the NEXT link (to page 2)
itemSelector : "#container .box",
// selector for all items you'll retrieve
extraScrollPx: 10,
}
);
【问题讨论】:
标签: php mysql pagination infinite-scroll