我正在尝试使用无限滚动插件(https://github.com/pklauzinski/jscroll)和PHP代码(PDO)。必须加载的内容是html-php文件,它在index.php中链接。一定很容易,但我无法理解,如何正确使用链接的html-php文件(我必须重复html结构吗?我必须第二次连接到数据库吗?如何从索引中停止的同一点继续获取。 php?一般如何实现?)
的index.php
JS / jQuery:
<script>
$('#posts').jscroll();
$(function() {
$('#posts').jscroll({
loadingHtml: '<br/><span>Loading...</span>',
padding: 20,
nextSelector: 'a.jscroll-next:last',
contentSelector: 'div',
autoTrigger:true
});
</script>
php代码:
session_start();
if ( isset( $_SESSION['login'] ) ) {
$login = $_SESSION['login'];
$id=$_SESSION['id'];
$username="root";
$password="root";
$hostname = "localhost";
$dbname= "kotik";
function testdb_connect ($hostname, $username, $password){
$dbh = new PDO("mysql:host=$hostname;dbname=kotik", $username, $password);
return $dbh;
}
try {
$dbh = testdb_connect ($hostname, $username, $password);
/* echo 'Connected to database'; */
} catch(PDOException $e) {
echo $e->getMessage();
}
html中的php代码:
<div id="posts" style="position:relative;width:100%;">
<?php
$title_select_query= $dbh -> prepare("SELECT title FROM books WHERE id = :id ORDER BY date DESC");
$title_select_query ->execute(array(':id' => $id));
$title_select_query_result = $title_select_query->fetchColumn();
echo('<div style="display:table; width:100%;"><div style="display:table-cell;vertical-align: middle;width:100%;height:100px;position:relative;text-indent: 1.5em;font-family:esq;color:#5b5b5b;font-size:23px;border-bottom:6px solid #F3F3F3; ">');
print("$title_select_query_result ");
echo('</div></div>');
$title_select_query_result = $title_select_query->fetchColumn();
echo(' <div style="display:table; width:100%;"> <div style="width:100%;height:100px;background:white;position:relative;border-bottom:6px solid #F3F3F3;text-indent: 1.5em;font-family:esq;color:#5b5b5b;font-size:23px;border-bottom:6px solid #F3F3F3;display:table-cell;vertical-align: middle;">');
print("$title_select_query_result ");
echo('</div><a href="loadmore.php"></a></div>');
?>
</div>
那么,根据我们在index.php中的内容继续获取列,链接文件中必须包含哪些内容?