1 回答

TA貢獻1871條經驗 獲得超13個贊
您可以通過獲取分頁所在的當前頁面所需的數據集來實現此目的,而不是獲取查詢返回的所有數據集。
例如:
想象一下你在分頁的第 1 頁。如果你每頁只需要 100 個項目,那么你可以將查詢檢索的項目限制為 100 個,這樣可以更快地檢索數據,因為而不是獲取每個數據從查詢中設置您剛剛獲得 100 以顯示在當前頁面中。
您必須在網址中傳遞頁碼。想象一下您的網址就像下面提到的那樣。
http://localhost/pagination.php?page=2
// getting the current page to set the starting point to get data.
if (isset($_GET['page'])) {
$curPage = $_GET['page'];
} else {
$curPage = 1;
}
//number of items you need per a page
$labels_per_page = 100;
//setting the starting point according to the page no.
if($curPage>1){
$start = ($curPage-1)*$labels_per_page;
}else{
$start = 0;
}
//limiting the query according to the starting point nd items per page
$sql = "SELECT id, DATE_FORMAT(tranDate,'%Y-%m-%d') as tranDate, tranTime, date, cmd, paymethod, amount, orgRefNo, orgTranDate FROM noti_card_data WHERE mbrNO = '1' LIMIT ".$start .','.$labels_per_page ;
結果視圖
我要查看
- 1 回答
- 0 關注
- 133 瀏覽
添加回答
舉報