PHP Universal Paging Class
?
Getallpage ()} page, {$page->getcurrentpage ()} page "; $links = $this->getlinkstring ($param); if ($page->hasprevious ()) $temp. = "Getcurrentpage ()-1)." ' > Previous page "; else{$temp. =" Prev ";} for ($i = $page->getcurrentpage (); $i <= $page->getallpage () && $i <= $page->getperrecords (); $i + + {$temp. = "{$i}";} if ($page->hasnext ()) $temp. = "Getcurrentpage () +1)." ' > next page "; else{$temp. =" Next page ";} return $temp;} Public Function getlinkstring ($param) {$str = "", $attr =$_get;unset ($attr [$param]), if ($attr) {foreach ($attr as $key = > $val) {if ($str = = "") {$str. = "? $key = $val";} else{$str. = "& $key = $val";}} $str. = "& $param";} else{$str. = "$param";} return $str;}}? >
??
Allpage;} /** * @return The $allRecords */public function getallrecords () {return $this->allrecords;} /** * @return The $perRecords */public function getperrecords () {return $this->perrecords;} /** * @return The $currentPage */public function getcurrentpage () {return $this->currentpage;} /** * @param $allPage the $allPage to set */public function Setallpage ($allPage) {$this->allpage = ($allPage% $this Perrecords = = 0)? ($allPage/$this->perrecords):($allPage/$this->perrecords+1); $this->allpage=intval ($this->allpage);} /** * @param $allRecords the $allRecords to set */public function Setallrecords ($allRecords) {$this->allrecords = $allR Ecords;} /** * @param $perRecords the $perRecords to set */public function Setperrecords ($perRecords) {$this->perrecords = $perR Ecords;} /** * @param $currentPage the $currentPage to set */public function Setcurrentpage ($currentPage) {if ($currentPage < 1) $this->currentpage = 1;else if ($currentPage > $this->allpage) $thIs->currentpage = $this->allpage;else$this->currentpage= $currentPage;} Public Function Hasnext () {return $this->currentpage< $this->allpage;} Public Function hasprevious () {return $this->currentpage>1;} Public Function Getendindex () {return (($this->currentpage-1) * $this->perrecords) + $this->perrecords) >$ This->allrecords? ((($this->currentpage-1) * $this->perrecords) + $this->perrecords)-$this->allrecords: $this Perrecords;} Public Function Getstartindex () {return ($this->currentpage-1) * $this->perrecords;}}? >
?
list= $list; $this->page=new page ();} /** * * @param unknown_type $rows The amount of data displayed * @param unknown_type $current Current page */public function init ($rows =5, $current) {$thi S->page->setallrecords (Count ($this->list)), $this->page->setperrecords ($rows); $this->page- >setallpage (Count ($this->list)), $this->page->setcurrentpage ($current), $this->list=array_slice ($ This->list, $this->page->getstartindex (), $this->page->getendindex ());} /** * Get paging variable */public function GetVar () {return $this->list;} /** * @return The $param */public function GetParam () {return $this->param;} /** * @param $param the $param to set */public function SetParam ($param) {$this->param = $param;} /** * Load plugin information, get generated link, adorner mode * @param unknown_type $link */public function GetLink ($link =null) {if (!empty ($link) | |! (($link instanceof ILink))) $link =new LinkAdapter (); return $link->parse ($this->page, $this->param);}}? >
?
SetParam ("page"), $page->init (30,$_request[' page '), $list = $page->getvar (); foreach ($list as $val): Echo $val. '
'; Endforeach;echo $page->getlink ();? >
? download