There is such an ajax handler, each time the $num variable is decremented by 12:
Get: 32/12 rowsGet: 20/12 rowsGet: 8/12 rowsGet: 0/12 rows
As can be seen from the last row of the record that will be output this Get: 8/12 rows if subtract 8-12=-4 then the records will no longer be displayed. But we still have 8 entries left. How can I get them out? How to do the processing? It should be like Get: 0/8 rows
$mesgs = $db->QueryFetchArrayAll("SELECT a.id, a.aut, a.mesg, a.timestamp, b.name, b.email FROM txt_mesgs a LEFT JOIN users b ON b.id = a.aut WHERE a.tid = '".$id."' ORDER BY a.timestamp ASC LIMIT 0, ".$num.""); And also if in the table for example 15 records, then you need to output the rest (3) Get: 0/3 rows
<?php if (isset($_POST['num']) && isset($_POST['tid']) && is_numeric($_POST['num']) && is_numeric($_POST['tid'])) { $num = $db->EscapeString($_POST['num']); $id = $db->EscapeString($_POST['tid']); if ($num > 0) { $mesgs = $db->QueryFetchArrayAll("SELECT a.id, a.aut, a.mesg, a.timestamp, b.name, b.email FROM txt_mesgs a LEFT JOIN users b ON b.id = a.aut WHERE a.tid = '".$id."' ORDER BY a.timestamp ASC LIMIT ".$num.", 12"); foreach($mesgs as $mesg){ ?> <div id="<?=$mesg['id']?>" class="ticket_mmesg"> <img class="ticket_mavatar" src="http://www.gravatar.com/avatar/<?=md5(strtolower(trim($mesg['email'])))?>?s=45" alt="<?=ucfirst($mesg['name'])?>" /> <div class="ticket_mtime-name"><div class="ticket_musername"><?=ucfirst($mesg['name'])?></div><div class="ticket_mtime"><?=date('H:i', $mesg['timestamp'])?></div></div> <div class="ticket_mdelete"></div> <div class="ticket_mtext"><?=$mesg['mesg']?></div> </div> <?php } } else { $db->Close(); echo 0; } }else{ echo 'Error'; } ?> -
$(document).ready(function () { var check_messages = setInterval(function () { var scrollPosition = $('#ticket_mscroll').scrollTop(); if (scrollPosition == 0) { load_tickets(); } }, 1000); var num = 32; //Всего у нас 56 сообщений, 56-24 =32 (На экране 12 сообщений уже выведено) function load_tickets() { var tid = 1; $.ajax({ url : "get.php", type : "POST", data : { "num" : num, "tid" : tid, }, cache : false, success : function (las_messages) { if (las_messages == 0) { // смотрим ответ от сервера и выполняем соответствующее действие //$(".ticket_mhead").append("<div> Error </div>"); clearInterval(check_messages); } else { $("#doload").prepend(las_messages+' '+num+'/12'); num = num - 12; } } }); } });
ajaxor reducingnum, but only sampling and rendering 12 records from tables starting at$num. So it is better for you to include yourajaxpart in the question. - teran