This tutorial provides you with a discuz forum style paging code. We wrote this code into a function. Let’s take a look.
This tutorial provides you with a discuz forum style paging code. We wrote this code into a function. Let’s take a look.
//Paging is the number of pages
function getPage($page,$pageSize){
$this->getRowsCount();
$this->getPageCount($pageSize) ;
//print $this->pageCount;
if(($page ==="") || ($page<"1") || (!ereg("[0-9]+ ",$page))){
$this->notePage = "1";
}else if($page>$this->pageCount){
$this->notePage = $this->pageCount;
}else{
$this->notePage = $page;
}
return $this->notePage;
}
//Get the total number of records
function getRowsCount(){
$this->getRes($this->sql_number);
$row = $this->getRows();
$this->number = $row[0];
return $this->number;
}
//Get the number of pages
function getPageCount($pageSize ){
$this->pageCount = ceil($this->number/$pageSize);
return $this->pageCount;
}
//Paging code
function getPageContent($page,$url,$pageSize){
if($page=="1"){
$view.=" [Home]";
$view.= " [Previous page]";
}else{
$view.=" [Home]";
$view.=" [Previous page]";
}
if ($page<$this->pageCount){
$view.=" [Next page] ";
$view.=" [Last page]" ;
}else{
$view.=" [Next page]";
$view.=" [Last page]";
}
return $view." Current page ".$page."Page/Total".$this->pageCount."Page".$this->number."Record"." Go to page ".$this->getUrl($url,$ page);
}
//Page to page
function getUrl($url,$page){
$go =" page
";
return $go;
}
//Jump page
function refUrl($url, $speak){
print("");
}