php分頁資料最後一頁繼續追加第一頁資料

2021-09-05 09:56:04 字數 1116 閱讀 4531

一般情況我們寫資料分頁都是如下**

//分頁碼

$page

=$_request

['page'];

//顯示條數

$limit=10

;//分頁開始條數

$start_limit=(

$page-1

)*$limit

;//執行sql語句得到的結果

$list

=model

('table')-

>

limit

("$start_limit

, $limit")

->

findall()

;//返回資料

return

$list

;

比如我們有102條資料,到了11頁的時候就會只有2條資料,顯然這不是我們要的結果。如果我們想要第11頁資料顯示的是最後的2條+第1頁的前8條,就不能用這種方法了。

//分頁碼

$page

=$_request

['page'];

//顯示條數

$limit=10

;//資料總條數

$count

=model

('table')-

>

count()

;//取模

$pattern=(

($page-1

)*$limit)%

$count

;//餘條數

$pattern_limit

=$pattern

%$limit

;//獲取資料

$list

=model

('table')-

>

limit

("$pattern

, $limit")

->

findall()

;//資料條數小於頁面顯示條數 繼續查詢進行追加if(

count

($list

)<

$limit

)return

$list

;

php分頁資料最後一頁繼續追加第一頁資料

一般情況我們寫資料分頁都是如下 分頁碼 page request page 顯示條數 limit 10 分頁開始條數 start limit page 1 limit 執行sql語句得到的結果 list model table limit start limit,limit findall 返回資料...

vue中刪除最後一頁的資料

在刪除方法裡進行以下操作 var maxpage math.ceil this total 1 當頁的條數 向上取整 console.log this.total console.log maxpage if this pagenum maxpage this getlist this pagenu...

jq 滑動到底部 載入下一頁資料

page num page num 1 頁碼自動增加,保證下次呼叫時為新的一頁。ajax beforesend function error function data 初始化載入第一頁資料 getdata 1 function insertdiv data,page num,pagenumber ...