文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>PHP一个分页类

PHP一个分页类

时间:2008-05-29  来源:剑心通明

以下为引用的内容:
class PageBar
{
        var $total;        
        var $onepage;
        var $num;                        
        var $pagecount;
        var $total_page;
        var $offset;        
        var $linkhead;        
   
        function PageBar($total, $onepage, $form_vars='')
        {
                $pagecount = $_GET['pagecount'];
                $this->total      = $total;
                $this->onepage    = $onepage;
                $this->total_page = ceil($total/$onepage);
                if (empty($pagecount))
                {
                        $this->pagecount = 1;
                        $this->offset         = 0;        
                }
                else
                {
                        $this->pagecount = $pagecount;
                        $this->offset    = ($pagecount-1)*$onepage;
                }
               
                if (!empty($form_vars))
                {
                        
                        $vars = explode("|", $form_vars);
                        $chk = $vars[0];
                        $chk_value = $_POST["$chk"];
                        if (empty($chk_value))
                        {
                                $formlink = "";
                        }
                        else
                        {
                                for ($i=0; $ilinkhead = $_SERVER['PHP_SELF']."?".$formlink;
                }
                else
                {
                        $linkft    = (substr($linkft, -1)=="&")?$linkft:$linkft."&";
                        $this->linkhead = $_SERVER['PHP_SELF']."?".$linkft.$formlink;
                }
        }
        #End function PageBar();
        function offset()
        {
                return $this->offset;
        }
        #End function offset();
        function pre_page($char='')
        {
                $linkhead  = $this->linkhead;
                $pagecount = $this->pagecount;
                if (empty($char))
                {
                        $char = "[1)
                {
                        $pre_page = $pagecount - 1;
                        return "$char";
                }
                else
                {
                        return '';
                }
        }
        #End function pre_page();
        function next_page($char='')
        {
                $linkhead   = $this->linkhead;
                $total_page = $this->total_page;
                $pagecount  = $this->pagecount;
                if (empty($char))
                {
                        $char = "[>]";
                }
                if ($pagecount$char";
                }
                else
                {
                        return '';
                }
        }
        #End function next_page();
        function num_bar($num='', $color='', $left='', $right='')
        {
                $num       = (empty($num))?10:$num;
                $this->num = $num;
                $mid       = floor($num/2);
                $last      = $num - 1;
                $pagecount = $this->pagecount;
                $totalpage = $this->total_page;
                $linkhead  = $this->linkhead;
                $left      = (empty($left))?"[":$left;
                $right     = (empty($right))?"]":$right;
                $color     = (empty($color))?"#ff0000":$color;
                $minpage   = (($pagecount-$mid)$totalpage)
                {
                        $maxpage = $totalpage;
                        $minpage = $maxpage - $last;
                        $minpage = ($minpage$char";
                        }
                        $linkchar = "".$char."";
                        $linkbar  = $linkbar.$linkchar;
                }
                return $linkbar;
        }
        #End function num_bar();
        function pre_group($char='')
        {
                $pagecount   = $this->pagecount;
                $linkhead    = $this->linkhead;
                $num             = $this->num;
                $mid         = floor($num/2);
                $minpage     = (($pagecount-$mid)$num)?$minpage-$mid:1;
                return "".$char."";
        }
        #End function pre_group();
        function next_group($char='')
        {
                $pagecount = $this->pagecount;
                $linkhead  = $this->linkhead;
                $totalpage = $this->total_page;
                $num           = $this->num;
                $mid       = floor($num/2);
                $last      = $num;
                $minpage   = (($pagecount-$mid)$totalpage)
                {
                        $maxpage = $totalpage;
                        $minpage = $maxpage - $last;
                        $minpage = ($minpage>]":$char;
                $ngpagecount = ($totalpage>$maxpage+$last)?$maxpage + $mid:$totalpage;
                return "".$char."";
        }
        #End function next_group();
    function whole_num_bar($num='', $color='')
    {
        $num_bar    = $this->num_bar($num, $color);
        $pre_group  = $this->pre_group();
        $pre_page   = $this->pre_page();
        $next_page  = $this->next_page();
        $next_group = $this->next_group();
            return  $pre_group.$pre_page.$num_bar.$next_page.$next_group;
    }
        #End function whole_bar();
        
        function Jump_form()
        {
                $linkhead = $this->linkhead;
                $total          = $this->total_page;
                $form =
        
                function jump(linkhead, total, page)
                {
                        var pagecount = (page.value>total)?total:page.value;
                        var pagecount = (pagecount
      
         
        
               
      
        
EOT;
        return $form;
        }
        #End function Jump_form();
}
#End class PageBar;
/*****
        //example
$total = 1000;
$onepage = 20;
$pb       = new PageBar($total, $onepage);
$offset   = $pb->offset();
$pagebar  = $pb->whole_num_bar();
$jumpform = $pb->Jump_form();
echo $offset."
".$pagebar."
".$jumpform;
return:
   0
[][>>]
   
*****/

相关阅读 更多 +
排行榜 更多 +
辰域智控app

辰域智控app

系统工具 下载
网医联盟app

网医联盟app

运动健身 下载
汇丰汇选App

汇丰汇选App

金融理财 下载