Class pageview{ /** page **/ public $pageNo = 1; /** Page Size **/ Public $pageSize = 20; /** total number of pages **/ Public $pageCount = 0; /** total number of records **/ Public $totalNum = 0; /** offset, current page start Row **/ Public $offSet = 0; /** data per page **/ Public $pageData = Array (); /** whether there is a previous page **/ Public $hasPrePage = true; /** whether there is a next page **/ Public $hasNextPage = true; Public $pageNoList = Array (); Public $jsFunction = ' jsfunction '; /** * * @param unknown_type $count total number of rows * @param unknown_type $size Paging size * @param unknown_type $string */ Public function __construct ($count =0, $size =20, $pageNo =1, $pageData =array (), $jsFunction = ' jsfunction ') { $this->totalnum = $count;//Total Record Count $this->pagesize = $size;//Size per page $this->pageno = $pageNo; Calculate Total Pages $this->pagecount = ceil ($this->totalnum/$this->pagesize); $this->pagecount = ($this->pagecount<=0)? 1: $this->pagecount; Check PageNo $this->pageno = $this->pageno = = 0? 1: $this->pageno; $this->pageno = $this->pageno > $this->pagecount? $this->pagecount: $this->pageno; Calculate offset $this->offset = ($this->pageno-1) * $this->pagesize; Calculate if there is a previous page next page $this->hasprepage = $this->pageno = = 1? false:true; $this->hasnextpage = $this->pageno >= $this->pagecount? false:true; $this->pagedata = $pageData; $this->jsfunction = $jsFunction; } /** * Paging algorithm * @return */ Private Function Generatepagelist () { $pageList = Array (); if ($this->pagecount <= 9) { for ($i =0; $i < $this->pagecount; $i +) { Array_push ($pageList, $i + 1); } }else{ if ($this->pageno <= 4) { for ($i =0; $i <5; $i + +) { Array_push ($pageList, $i + 1); } Array_push ($pageList,-1); Array_push ($pageList, $this->pagecount); }else if ($this->pageno > $this->pagecount-4) { Array_push ($pageList, 1); Array_push ($pageList,-1); for ($i =5; $i >0; $i-) { Array_push ($pageList, $this->pagecount-$i + 1); } }else if ($this->pageno > 4 && $this->pageno <= $this->pagecount-4) { Array_push ($pageList, 1); Array_push ($pageList,-1); Array_push ($pageList, $this->pageno-2); Array_push ($pageList, $this->pageno-1); Array_push ($pageList, $this->pageno); Array_push ($pageList, $this->pageno + 1); Array_push ($pageList, $this->pageno + 2); Array_push ($pageList,-1); Array_push ($pageList, $this->pagecount); } } return $pageList; } /*** * Create a paging control * @param * @return String */ Public Function Echopageasdiv () { $pageList = $this->generatepagelist (); $pageString = ""; if (!empty ($pageList)) { if ($this->pagecount >1) { if ($this->hasprepage) { $pageString = $pageString. " Jsfunction. "(" . ($this->pageno-1). ")" > Previous page "; } foreach ($pageList as $k = = $p) { if ($this->pageno = = $p) { $pageString = $pageString. " " . $this->pageno. ""; Continue } if ($p = =-1) { $pageString = $pageString. " ..."; Continue } $pageString = $pageString. " Jsfunction. "(" . $p. ")" > ". $p. ""; } if ($this->hasnextpage) { $pageString = $pageString. " Jsfunction. "(" . ($this->pageno+1). ")" > Next page "; } } } $pageString = $pageString. (""); return $pageString; } } ?> |