php實現分頁顯示功能

2021-09-30 14:42:03 字數 1481 閱讀 6062

sql公式: select * from cz_goods_type order by type_id limit 1,2;

offset:偏移量

pagesize:每頁顯示的條數

其中offset是在變化的,和當前所在頁數(current)、每頁顯示條數有關(pagesize)

offset=(current-1) * pagesize

最終公式:select * from cz_goods_type order by type_id limit (current-1)*pagesize, pagesize;

分頁步驟:

1、查詢資料庫獲取記錄

2、使用分頁類輸出分頁資訊

分頁類只輸出分頁資訊,不負責查詢資料庫, 分頁類:

<?php

//分頁類,完成分頁資訊的輸出

class page

$str = implode("&", $temp); // p=admin&c=brand&a=index

$this->url = "$script?&page="; //由於上頁,下頁,首頁,末頁的page是不同的,不能指定

$this->first = $this->getfirst(); //得到首頁超連結

$this->last = $this->getlast();

$this->prev = $this->getprev();

$this->next = $this->getnext();

} //獲得首頁超連結

private function getfirst()else 1'>[首頁]";

} }//獲得末頁超連結

private function getlast() else '>[末頁]";

} }private function getprev() else

} private function getnext() else

} //主方法,輸出分頁資訊

public function showpage() 條記錄,每頁顯示 條記錄,

當前為 /

";} else

}}

使用方法:

model中的**:

//分頁獲取商品型別資料

public function getpagetypes($offset, $pagesize) order by type_id limit $offset, $pagesize";

return $this->db->getall($sql);

}

controller中使用的**:

public function indexaction()

view中用的方法:

<?php echo $pageinfo;?>

php後端分頁 PHP實現資料分頁顯示功能的方法

這篇文章主要為大家詳細介紹了基於php實現資料分頁顯示功能,分頁在後台管理中是經常使用的功能,分頁顯示方便大量資料的管理,感興趣的小夥伴們可以參考一下 實現 使用者列表 con mysql connect localhost root mysql query set names utf8 mysql...

PHP實現分頁瀏覽功能

入門級 class pages 方法名 db select 說明 執行資料庫連線以及sql查詢 返回值 查詢所得結果集 public function db select sql else return res mysqli close 方法名 print pages 引數 per page row...

php 實現分頁功能(class封裝了功能)

分頁是乙個很常見的功能,我這裡提供了分類類 class 用於前端頁面中的四個按鈕 首頁腳頁 上面的演示非常不直觀,但足可以證明這個類可以完成分頁功能。附有非常詳細的注釋,但需要有一定的 php 基礎。todo 分頁類 前端需傳遞兩個引數 請求方式 get num 每頁要顯示多少條資料 sum 一共有...