I am creating a simple messaging web application. People can easily send or recieve text sms by logging in. Just click on the specific contact name and you will have the chat box with all the previous messages . Now the problem is,any conversation that have lots of messages will take a long time to load the chatbox. So I want to show latest (order by by sendingtime desc) 10 messages in the chatbox for the first time. And at the top of the chat box I want to provide a button by clicking which user will get previous 10 messages (order by by sendingtime desc).And it will be continue till the user get the last msg. I am using PHP AJAX. Code I used to get first 10 messages is here
$sql2="select * from messages where sender='$user1' and reciever='$user2' or reciever='$user1' and
sender='$user2' order by sendingTime desc";
$res2=mysqli_query($con,$sql2);
$num=mysqli_num_rows($res2);
if($num<=10){
for($i=1;$i<=$num;$i++){
$row2=mysqli_fetch_array($res2);
$data2[]=$row2;
}
}else{
for($i=1;$i<=10;$i++){
$row2=mysqli_fetch_array($res2);
$data2[]=$row2;
}
}
But I have no idea how to select next 10 message rows. Please Help.
My 'messages' database structure
1 idPrimary int(11) No None AUTO_INCREMENT Change Change Drop Drop
More More
2 sender varchar(100) latin1_swedish_ci No None Change Change Drop Drop
More More
3 reciever varchar(100) latin1_swedish_ci No None Change Change Drop Drop
More More
4 msg varchar(5000) latin1_swedish_ci No None Change Change Drop Drop
More More
5 sendingTime varchar(100) latin1_swedish_ci No None Change Change Drop Drop
More More
6 deliveryTime varchar(100) latin1_swedish_ci No None Change Change Drop Drop
More More
7 status int(1) No