我有一个“显示更多”按钮的示例代码,我想为“显示较旧”消息在消息页面中更改它,并在消息顶部放置按钮。 该示例代码用于显示以前的帖子: a.php:
<div id="comnts"></div>
<button id="btn" >load more</button>
<script>
$(document).ready(function() {
var comco = 5;
var offset = 0;
$("#btn").click(function() {
$.ajax({
method: "POST",
url: "b.php",
data: { comnco: comco, offset: offset }
})
.done(function(msg) {
$("#comnts").append(msg);
});
offset = offset + comco;
});
$("button").trigger("click");
});
</script>
b.php:
$comnco=$_POST['comnco'];
$offset=$_POST['offset'];
$rzp=mysqli_query($conn,"
SELECT * FROM `tbl_users_posts` WHERE uid in (SELECT frname FROM t_frnd WHERE uname='$uid') UNION
SELECT * FROM `tbl_users_posts` WHERE uid='$uid' ORDER BY id DESC limit $offset, $comnco");
我不是专业程序员,因此在帮助下创建了此代码。 我试图更改mysql代码。这段代码显示了我想要的但不能正常工作:
$rzp=mysqli_query($conn,"SELECT * FROM t_msg WHERE
id > ((SELECT MAX(id) FROM t_msg) - '$comnco')
AND ( (for_u=1 AND u_sender=2)
OR (for_u=2 AND u_sender=1) )");
使用按钮或滚动olso进行此操作的示例代码对我有帮助。 谢谢