当前位置:Gxlcms > PHP教程 > php分页类(源码+实例)

php分页类(源码+实例)

时间:2021-07-01 10:21:17 帮助过:19人阅读

分享一个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<1) $end_conter=$end_conter+abs($start_counter);
    if($end_conter>$this->Pages) $start_counter=$start_counter-($end_conter-$this->Pages);
    if(($this->Page_number-floor($this->Buttons/2))<1)$end_conter ++;     
     
    for ($i=$start_counter;$i<=$end_conter;$i++) 
{ 
     
if($i>$this->Pages || $i<1)continue;        //no print less than 1 value or grater than totall page 
     
if($i==$this->Page_number)echo ' '.$i.' ';         // change current page' class 
     
else echo ' '.$i.' ';      // normal pages 
     
} 
      
    //echo next button 
     
    if($this->Page_number<$this->Pages)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.org 
 

Start , $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.org 
 
Start , $cat->End 

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

人气教程排行