欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

php 分页类(源码+实例)

程序员文章站 2022-05-17 13:01:58
...
分享一个php分页类,写的不错,提供了二个该分页类的调用实例,供大家学习参考。

1,php分页类代码

        Number        =    $number;
    $this->        N_p_p        =    $n_p_p; 
    $this->        Pages        =    ceil    (    $this->    Number    /    $this->    N_p_p    )    ; 
    $this->        Buttons        =    $buttons        ; 
    $page_number=    ($page_number>$this->Pages)    ?    $this->Pages    :    $page_number    ; 
    $this->        Page_number    =    $page_number    ; 
    $this->        Ret()    ; 
    } 

 public function Show_Pagination($link,$get='page',$div_class_name='pagination') 
    { 

    //if pages == 1 , no need to print pagination 
    if($this->Pages==1)return; 
    //$link is the addres of current page      
    //$get is name of get method 
    //echo pagination's div 
     
    echo'
'; //echo pre button if($this->Page_number>1)echo 'Page_number -1 ).'">Per '; else echo 'Per '; //print button $this->Buttons=(int)$this->Buttons; $start_counter = $this->Page_number-floor($this->Buttons/2);//for normal mode $end_conter = $this->Page_number+floor($this->Buttons/2);//for normal mode //try to buttons exactly equal to $Buttons if($start_counter$this->Pages) $start_counter=$start_counter-($end_conter-$this->Pages); if(($this->Page_number-floor($this->Buttons/2))$this->Pages || $iPage_number)echo ' '.$i.' '; // change current page' class else echo ' '.$i.' '; // normal pages } //echo next button if($this->Page_numberPages)echo 'Page_number +1 ) .'">Nex '; else echo 'Nex '; //close div tag echo'
'; } //give the page number and return start and end of selection private function Ret() { $this->Start=(($this->Page_number-1)*$this->N_p_p); $this->End= $this->N_p_p ; } }

2,分页类的示例一

 
php分页类示例---bbs.it-home.orgStart , $pagination->End"); 

//echo your result 
while($row=mysql_fetch_assoc($SecondQuery)) 
    { 
        echo 'id='.$row['id'].'
'; } //show pagination: $pagination->Show_Pagination("ExampleMysql.php?param1=value1",'page','pagination'); ?>

3,分页类的调用示例二

 
php分页类的调用示例-bbs.it-home.orgStart , $cat->End 

//for show : 
$cat->Show_Pagination("example.php?",'page','pagination'); 
?>