我已經在php中完成了分頁。但在某些記錄之后,它會顯示某些行的重復條目。我的查詢是第一次加載頁面時select * from sakhe WHERE status = 1 ORDER BY sakhe_id ASC limit 0,30我在第二次滾動時的查詢(它在一次滾動時執行了兩次)select * from sakhe WHERE status = 1 ORDER BY sakhe_id ASC limit 30,30在此查詢之后,我在控制臺中找到了正確的數據。但它在現場顯示重復。我的 Js 代碼是這樣的var page = 1;var total_page = "";function getresult(searches) { $.ajax({ url: "process/Sakhe_list.php", type: "post", data: { Sakhe_name: $("#Sakhe_name").val(), page: page }, success: function (data) { if (searches == true) { $("#rows").html(data); } else { $("#rows").append(data); } } });}$(document).ready(function () { getresult(false); $(window).scroll(function () { if ($(window).scrollTop() >= $(document).height() - $(window).height() - 5) { if ($(".current_page:last").val() <= $("#total_page").val()) { page = parseInt($(".current_page:last").val()) + 1; getresult(false); } } }); $("#shopsubmit").click(function () { page = 1; getresult(true); }); $("#reset").click(function () { $("#Sakhe_name").val(""); page = 1; getresult(true); });目前我正在獲得最后 7 條重復記錄。
2 回答

明月笑刀無情
TA貢獻1828條經驗 獲得超4個贊
你的searches == true情況有問題。那是每次在 HTML 中附加數據的時候。修理它。它會正常工作。簡單的刪除條件并使用以下代碼:
if(data !== 'undefined' && data !== '') {
$("#rows").html(data);
}

哈士奇WWW
TA貢獻1799條經驗 獲得超6個贊
如果顯示重復數據,則可以使用 DISTINCT 關鍵字從查詢中修復
select DISTINCT from sakhe WHERE status = 1 ORDER BY sakhe_id ASC limit 0,30
和:
select DISTINCT from sakhe WHERE status = 1 ORDER BY sakhe_id ASC limit 30,30
- 2 回答
- 0 關注
- 354 瀏覽
添加回答
舉報
0/150
提交
取消