如果滚动到页面底部,如何从数组中加载更多内容。 所以只有前5个"项目"如果显示,如果您滚动到底部,则会显示下5个,因此浏览器不会崩溃。 我的阵列:
$statement = $pdo->prepare("SELECT * FROM actvt");
$statement->execute();
$users = $statement->fetchAll();
foreach($users as $row) {
echo $row("username");
}
答案 0 :(得分:0)
PHP
function callMore(){
$last_appt = $_POST['last_result'];
$statement = $pdo->prepare("SELECT * FROM actvt WHERE date = ".$last_appt." limit = X "); //not sure your table structure , X is how many you want to load
foreach($statement as $val){
//Set your gathered results here
}
return X //return the results to your ajax call
}
js / ajax call
$.ajax({
type: 'POST',
data: {
action: 'callMore',
lastPost : XXXX //Put your last post here
},
success : function(msg){
//Do something with returned data append where ever
},
datatype: 'json',
});
从这里你需要检测你何时到达最后一篇文章...我建议你检测你何时在页面底部,如果你在最后一篇文章中使用jquery使用scrollTop,那就找它的Y值,然后窗口偏移量,滚动触发,如果你接近底部,则触发。你已经到达底部,运行你的ajax函数并检索下一个结果。
答案 1 :(得分:-1)
所以你可以像load.php一样创建......
$start=$_GET["page"]*100;//100 entries
$statement = $pdo->prepare("SELECT * FROM actvt ");
$statement->execute();
$users = $statement->fetchAll();
$counter=0;
foreach($users as $row) {
$counter++;
if($counter>$start && $counter <=$start+100){//100 entries
echo $row("username");
}
}
if($counter<$row.length){
echo "<a href='?page=".($page+1)."'>Next Page</a>";
}
现在你可以打电话给“http://yourpage?page=10”......
js部分足以填补另一个答案......