我正在尝试为像facebook这样的用户朋友系统制作一个无限滚动页面。但我有一个问题。我的PHP代码重复相同的结果。我在这里想念的是谁能在这方面帮助我?
<div id="dataList">
<div data-Fid="1"></div>
<div data-Fid="12"></div>
<div data-Fid="9"></div>
<div data-Fid="26"></div>
<div data-Fid="27"></div> <-- lastID ==> friend_id
</div>
<div class="p_user" data-kid="5"></div>
我的ajax代码:
$(window).scroll(function () {
if (scrollKLoad && $(window).scrollTop() >= $(document).height() - $(window).height() - 300) {
scrollKLoad = false;
var ID = $('#dataList').children().last().attr('data-Fid');
var P_ID = $('.p_user').attr('data-kid');
var newcontent = '<div class="postBody"><div class="glbD0w">No more user</div></div>';
var dataString = "lastID=" + ID +"&pID=" + P_ID;
if (ID) {
$.ajax({
type: "POST",
url: '/requests/morefriend.php',
data: dataString,
cache: false,
beforeSend: function() {
// Do something
},
success: function(html) {
if(html) {
$("#dataList").append(html);
} else {
$('#dataList').append(newcontent);
}
}
});
} else {
$("#more").html('The End');
}
return false;
}
});
和我的PHP代码:
public function FolloWingUserList($uid,$lastID) {
$uid=mysqli_real_escape_string($this->db,$uid);
if($lastID) {
$lastID = "AND F.friend_id > '".$lastID."'";
}
// The query to select for showing user details
$query=mysqli_query($this->db,"SELECT U.username,U.name,U.uid,F.friend_id FROM users U, friends F WHERE U.status='1' AND U.uid=F.friend_two AND F.friend_one='$uid' AND F.friend_one='$uid' AND F.role='fri' $lastID ORDER BY U.uid DESC LIMIT " .$this->perpage)or die(mysqli_error($this->db));
while($row=mysqli_fetch_array($query, MYSQLI_ASSOC)) {
$data[]=$row;
}
if(!empty($data)) {
// Store the result into array
return $data;
}
}