当前位置:Gxlcms > PHP教程 > PHP分页库

PHP分页库

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

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 < $total_page )
{
$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 ) < 1 ) ? 1 : ( $pageID - $mid ) ;
$maxpage = $minpage + $last ;
if ( $maxpage > $totalpage )
{
$maxpage = $totalpage ;
$minpage = $maxpage - $last ;
$minpage = ( $minpage < 1 ) ? 1 : $minpage ;
}

for ( $i = $minpage ; $i <= $maxpage ; $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 ) < 1 ) ? 1 : ( $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 ) < 1 ) ? 1 : ( $pageID - $mid ) ;
$maxpage = $minpage + $last ;
if ( $maxpage > $totalpage )
{
$maxpage = $totalpage ;
$minpage = $maxpage - $last ;
$minpage = ( $minpage < 1 ) ? 1 : $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 ( ' |< ' , $others ) ;
$pre_page = $this -> pre_page ( ' < ' , $others ) ;
$next_page = $this -> next_page ( ' > ' , $others ) ;
$next_group = $this -> next_group ( ' >| ' , $others ) ;

return $pre_group . $pre_page . $num_bar . $next_page . $next_group ;
}
}
?>

人气教程排行