- 論壇徽章:
- 0
|
2: #===============================================
3: # 名 稱: Page v1.1 分頁
4: # 文 件: Page.class.php
5: # 作 者: liu21st, liu21st@126.com
6: # 說 明: 實(shí)現(xiàn)分頁功能
7: # 修 改: 2003-12-23 加firstRow的溢出判斷,溢出時(shí)顯示最后一頁
8: #------------------------------------------------------------------------------------
9:
[color="#ff9900"] 10: class Page {
11: var $firstRow = 0 ; // 起始行
12: var $listRows = 0 ; // 每頁顯示列表行數(shù)
13: var $parameter = ""; // 頁數(shù)跳轉(zhuǎn)時(shí)要帶的參數(shù)
14: var $totalPages = 0 ; // 總頁數(shù)
15: var $totalRows = 0 ; // 總行數(shù)
16: var $nowPage = 0 ; // 當(dāng)前頁數(shù)
17: var $showPageJump = True; // 是否顯示跳到第幾頁
18: var $coolPages = 0 ; // 分頁的欄的總頁數(shù)
19: var $rollPage = 5; // 分頁欄每頁顯示的頁數(shù)
20:
21: /*--------------------------------------------------------------------------
22: 功能:顯示分頁信息第 x 頁 共 x 頁 >>
23: -----------------------------------------------------------------------------*/
24: function prompt() {
25: if(0 == $this->totalRows) {
26: return;
27: }
28: $this->totalPages=ceil($this->totalRows/$this->listRows); //總頁數(shù)
29: $this->coolPages = ceil($this->totalPages/$this->rollPage);
30: if ( $this->firstRow >= $this->totalRows ) { // 2003-12-30 17:18:29 kinger modified
31: $this->nowPage = $this->totalPages;
32: $this->firstRow = ($this->totalPages-1)*$this->listRows;
33: } else {
34: $this->nowPage=floor($this->firstRow/$this->listRows+1); //當(dāng)前頁號(hào)
35: }
36: $nowCoolPage = ceil($this->nowPage/$this->rollPage);
37:
38: // >>
39: if($nowCoolPage == 1){
40: $theFirst = "";
41: $prePage = "";
42: }else{
43: $preRow = ($this->rollPage*($nowCoolPage-1)-1)*$this->listRows;
44: $prePage = "totalRows&$this->parameter'>";
45: $theFirst = "totalRows&$this->parameter'>";
46: }
47: if($nowCoolPage == $this->coolPages){
48: $nextPage = "";
49: $theEnd="";
50: }else{
51: $nextRow = ($nowCoolPage*$this->rollPage)*$this->listRows;
52: $theEndRow = ($this->totalPages-1)*$this->listRows;
53: $nextPage = "totalRows&$this->parameter'>>";
54: $theEnd = "totalRows&$this->parameter'>>>";
55: }
56: // 1 2 3 4 5
57: $linkPage = "";
58: for($i=1;$i$this->rollPage;$i++){
59: $page=($nowCoolPage-1)*$this->rollPage+$i;
60: $rows=($page-1)*$this->listRows;
61: if($page!=$this->nowPage){
62: if($page$this->totalPages){
63: $linkPage .= " totalRows&$this->parameter'>".$page."";
64: }else{
65: break;
66: }
67: }else{
68: if($this->totalPages != 1){
69: $linkPage .= " [".$page."]";
70: }
71: }
72: }
73: $pageStr = "共 $this->totalPages 頁 ".$theFirst." ".$prePage." ".$linkPage." ".$nextPage." ".$theEnd;
74: return $pageStr;
75: }
76: /*-----------------------------------------------------------------------
77: 使用舉例。
78: --------------------------------------------------------------------
79: $page = new Page();
80: if ($totalRows){
81: $page->totalRows=$totalRows;
82: }else{
83: //此處為計(jì)算查詢個(gè)數(shù),視不同的數(shù)據(jù)庫方式有所不同
84: $page->totalRows=$db->count($db->select("user","*"););
85: }
86: $page->listRows="2";
87: if ($firstRow){
88: $page->firstRow=$firstRow;
89: }else{
90: $page->firstRow=0;
91: }
92: $db->select("user","*","","","$page->firstRow,$page->listRows");
93: while($db->nextRecord()) {
94: echo $db->record[id]." ";
95: echo $db->record[name]." ";
96: echo $db->record[age]." ";
97: echo "
";
98: }
99: $pager=$page->prompt();
100: -------------------------------------------------------------------------------*/
101: }
102: ?>
下載地址
本文來自ChinaUnix博客,如果查看原文請(qǐng)點(diǎn):http://blog.chinaunix.net/u/2633/showart_22025.html |
|