Heim >Backend-Entwicklung >PHP-Tutorial >PHP分页库
class PageBar
{
var $total ;
var $onepage ;
var $num ;
var $pageID ;
var $total_page ;
var $linkhead ;
function PageBar ( $total , $onepage )
{
$pageID = $_GET [ ' pageID ' ] ;
$this -> total = $total ;
$this -> onepage = $onepage ;
$this -> total_page = @ ceil ( $total / $onepage ) ;
if ( empty ( $pageID ))
{
$this -> pageID = 1 ;
$this -> offset = 0 ;
}
else
{
$this -> pageID = $pageID ;
$this -> offset = ( $pageID - 1 ) * $onepage ;
}
$linkarr = explode ( " &pageID= " , $_SERVER [ ' QUERY_STRING ' ]) ;
$linkft = $linkarr [ 0 ] ;
$self = str_replace ( " index.php " , "" , $_SERVER [ ' PHP_SELF ' ]) ;
if ( empty ( $linkft ))
$this -> linkhead = $self . " ? " . $formlink ;
else
$this -> linkhead = $self . " ? " . $linkft . $formlink ;
}
function pre_page ( $char = '' , $others = '' )
{
$linkhead = $this -> linkhead ;
$pageID = $this -> pageID ;
if ( $pageID > 1 )
{
$pre_page = $pageID - 1 ;
if ( $others )
return " $char " ;
else
return " $char " ;
}
else
return '' ;
}
function next_page ( $char = '' , $others = '' )
{
$linkhead = $this -> linkhead ;
$total_page = $this -> total_page ;
$pageID = $this -> pageID ;
if ( $pageID {
$next_page = $pageID + 1 ;
if ( $others )
return " $char " ;
else
return " $char " ;
}
else
return '' ;
}
function num_bar ( $num = '' , $color = '' , $others = '' , $left = '' , $right = '' )
{
$num = ( empty ( $num )) ? 10 : $num ;
$this -> num = $num ;
$mid = floor ( $num / 2 ) ;
$last = $num - 1 ;
$pageID = $this -> pageID ;
$totalpage = $this -> total_page ;
$linkhead = $this -> linkhead ;
$left = ( empty ( $left )) ? " [ " : $left ;
$right = ( empty ( $right )) ? " ] " : $right ;
$color = ( empty ( $color )) ? " #ff0000 " : $color ;
$minpage = (( $pageID - $mid ) $maxpage = $minpage + $last ;
if ( $maxpage > $totalpage )
{
$maxpage = $totalpage ;
$minpage = $maxpage - $last ;
$minpage = ( $minpage }
for ( $i = $minpage ; $i {
$char = $left . $i . $right ;
if ( $i == $pageID )
$linkchar = " $char " ;
else
$others ? $linkchar = " " . $char . " " : $linkchar = " " . $char . " " ;
$linkbar = $linkbar . $linkchar ;
}
return $linkbar ;
}
function pre_group ( $char = '' , $others = '' )
{
$pageID = $this -> pageID ;
$linkhead = $this -> linkhead ;
$num = $this -> num ;
$mid = floor ( $num / 2 ) ;
$minpage = (( $pageID - $mid ) $pgpageID = ( $minpage > $num ) ? $minpage - $mid : 1 ;
if ( $pageID != $minpage )
$others ? $linkHerf = " " . $char . " " : $linkHerf = " " . $char . " " ;
else
$linkHerf = $char ;
return $linkHerf ;
}
function next_group ( $char = '' , $others = '' )
{
$pageID = $this -> pageID ;
$linkhead = $this -> linkhead ;
$totalpage = $this -> total_page ;
$num = $this -> num ;
$mid = floor ( $num / 2 ) ;
$last = $num ;
$minpage = (( $pageID - $mid ) $maxpage = $minpage + $last ;
if ( $maxpage > $totalpage )
{
$maxpage = $totalpage ;
$minpage = $maxpage - $last ;
$minpage = ( $minpage }
$ngpageID = ( $totalpage > $maxpage + $last ) ? $maxpage + $mid : $totalpage ;
if ( $pageID == $maxpage || $maxpage == 0 )
$linkHerf = $char ;
else
$others ? $linkHerf = " " . $char . " " : $linkHerf = " " . $char . " " ;
return $linkHerf ;
}
function whole_num_bar ( $num = '' , $color = '' , $others = '' )
{
$num_bar = $this -> num_bar ( $num , $color , $others ) ;
$pre_group = $this -> pre_group ( ' | $pre_page = $this -> pre_page ( ' $next_page = $this -> next_page ( ' > ' , $others ) ;
$next_group = $this -> next_group ( ' >| ' , $others ) ;
return $pre_group . $pre_page . $num_bar . $next_page . $next_group ;
}
}
?>