i have a sample code for a "show more" button and i want to change it for "show older" messages in a message page and place button in the top of messages. the sample code is used to display previous posts: 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");
I am not a professional programmer and I created this code with help. i tried to change the mysql code. this code shows what i want but does not work properly:
$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) )");
a sample code for doing this with button or scroll olso helps me. thanks