PHP分类库
作者: 天行
可以换换链接。生成HTML的时候
<?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 "<a href=\"$others"."$pre_page\">$char</a>";
else
return "<a href=\"$linkhead"."&pageID=$pre_page$others\">$char</a>";
}
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 "<a href=\"$others"."$next_page\">$char</a>";
else
return "<a href=\"$linkhead"."&pageID=$next_page$others\">$char</a>";
}
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 = "<font color='$color'>$char</font>";
else
$others ? $linkchar = "<a href='$others"."$i'>".$char."</a>":$linkchar = "<a href='$linkhead"."&pageID=$i$others'>".$char."</a>";
$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 = "<a href='$others"."$pgpageID'>".$char."</a>":$linkHerf = "<a href='$linkhead"."&pageID=$pgpageID$others'>".$char."</a>";
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 = "<a href='$others"."$ngpageID'>".$char."</a>":$linkHerf = "<a href='$linkhead"."&pageID=$ngpageID$others'>".$char."</a>";
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;
}
}
?>
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 "<a href=\"$others"."$pre_page\">$char</a>";
else
return "<a href=\"$linkhead"."&pageID=$pre_page$others\">$char</a>";
}
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 "<a href=\"$others"."$next_page\">$char</a>";
else
return "<a href=\"$linkhead"."&pageID=$next_page$others\">$char</a>";
}
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 = "<font color='$color'>$char</font>";
else
$others ? $linkchar = "<a href='$others"."$i'>".$char."</a>":$linkchar = "<a href='$linkhead"."&pageID=$i$others'>".$char."</a>";
$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 = "<a href='$others"."$pgpageID'>".$char."</a>":$linkHerf = "<a href='$linkhead"."&pageID=$pgpageID$others'>".$char."</a>";
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 = "<a href='$others"."$ngpageID'>".$char."</a>":$linkHerf = "<a href='$linkhead"."&pageID=$ngpageID$others'>".$char."</a>";
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;
}
}
?>
你确定这不是分页类?我看了一部分就觉得这是分页的,大虾您要是真比较懂这个,帮我到那论坛里面(http://www.phpwind.net/read-htm-tid-279086.html)看看我那有疑问的无限分类,就是代码那块我不太懂,因为写得不是很具体但逻辑上也还说得过去。