您好,欢迎访问一九零五行业门户网

完善的page分页模块,和百度一模一样

http://www.schoolcms.cn/ 发布
完善的page分页模块,和百度一模一样
m_pagingdataarray = array();
        $this->m_configuration = array();
/* 基础数据设置 */
        $this->setpagingdataarray($pagingdataarray);
        $this->setconfiguration($configuration );
        $this->setbasisdata();
    }
/*
        设置数据
    */
    private function setpagingdataarray($pagingdataarray)
    {
        /* 判断配置项的数据是否为空 */
        if(false == empty($pagingdataarray)) {
            $this->m_pagingdataarray = $pagingdataarray;
        } else {
            $this->m_pagingdataarray = array();
        }
    }
/*
        设置配置项数据
    */
    private function setconfiguration($configuration)
    {
        /* 判断配置项的数据是否为空 */
        if(false == empty($configuration)) {
            $this->m_configuration = $configuration;
        } else {
            $this->m_configuration = array();
        }
    }
/*
        处理判断数组中是否存在某个键名
    */
    private function setuppase($property, $key, $content)
    {
        /* 判断 $key 是否在数组中存在的键名 */
        if(true == array_key_exists($key, $this->m_configuration)) {
            $this->$property = $this->m_configuration[$key];
        } else {
            $this->$property = $content;
        }
    }
/*
        基础数据设置
    */
    private function setbasisdata()
    {
        $this->setfraction();
        $this->settotal();
        $this->setpage();
        $this->setstarting();
        $this->settotalfraction();
        $this->seturl();
        $this->setpagecoent();
    }
/*
        设置每页显示数据的条数
    */
    private function setfraction()
    {
        $this->setuppase('m_fraction', 'traction', 15);
    }
/*
        设置数据的总条数
    */
    private function settotal()
    {
        $this->setuppase('m_total', 'total', 0);
    }
/*
        设置页面传递过来的页码值
    */
    private function setpage()
    {
        /* 判断 $key 是否在数组中存在的键名 */
        if(true == array_key_exists('page', $this->m_pagingdataarray)) {
            $this->m_page = max(1, (false == empty($this->m_pagingdataarray['page']) ? intval($this->m_pagingdataarray['page']) : 0));
        } else {
            $this->m_page = 1;
        }
    }
/*
        设置查询数据的起始值
    */
    private function setstarting()
    {
        $this->m_starting = ($this->m_page - 1) * $this->m_fraction;
    }
/*
        设置计算出来的总页数, 总页数 = 总条数除以每页显示的条数。
    */
    private function settotalfraction()
    {
        $this->m_totalfraction = ceil($this->m_total/$this->m_fraction);
/* 当前页数大于最大页数时,将总页数的值赋值给当前页面,防止超越操作。*/
        if($this->m_totalfraction m_page) {
            $this->m_page = $this->m_totalfraction;
        }
    }
/*
        设置分页的url地址
    */
    private function seturl()
    {
        $this->setuppase('m_url', 'url', null);
    }
/*
        设置是否开启显示数字分页按钮
    */
    private function setpagecoent()
    {
        $this->setuppase('m_pagecoent', 'pagecoent', 0);
    }
/*
    获取查询数据的起始值
    */
    public function getstarting()
    {
        return $this->m_starting;
    }
/*
        获取每页显示的条数值
    */
    public function getfraction()
    {
        return $this->m_fraction;
    }
/*
        获取拼接的每页显示的数字页码
    */
    private function getpagecoent($pageurl)
    {
        /* 如果page值不等于1的时候 */
        if($this->m_page != 1) {
            /* 如果分页数值加显示的分页个数值大于当前总页码数的时候 */
            if(($this->m_page+$this->m_pagecoent) > $this->m_totalfraction) {
                /* 计算起始值 */
                $pageis = $this->m_page-$this->m_pagecoent;
                /* 计算最大数值 */
                $pagemax = $this->m_totalfraction;
/* 如果分页数值加显示的分页个数值不大于当前总页码数的时候 */
            } else {
                /* 计算起始值,如果当前page小于等于显示的页数时,就将起始设置为1,防止负数 */
                if($this->m_page m_pagecoent) {
                    $pageis = 1;
                } else {
                    $pageis = $this->m_page-$this->m_pagecoent;
                }
/* 计算最大数值,当前page数值加需要显示的页码个数值 */
                $pagemax = (($this->m_page+$this->m_pagecoent));
            }
/* 如果显示页码值大于等于总页码值时,将起始值设置为1 */
            if($this->m_pagecoent >= $this->m_totalfraction) {
                $pageis = 1;
            }
/* 如果page等于1的时候 */
        } else {
            /* 如果显示页码值大于等于总页码值时,就将总页码值赋值给循环的最大值 */
            if($this->m_pagecoent >= $this->m_totalfraction) {
                $pagemax = $this->m_totalfraction;
            } else {
                $pagemax = $this->m_pagecoent+1;
            }
            $pageis = 1;
        }
/* 循环拼接需要显示的分页数值个数代码 */
        $pagecoent = '';
        for($pagei=$pageis; $pagei            if($this->m_page == $pagei) {
                $pagecoent .= ''.$pagei.'';
            } else {
                $pagecoent .= ''.$pagei.'';
            }
}
        /* 返回拼接好的代码 */
        return $pagecoent;
    }
/*
        获取url拼接,处理url拼接方法
    */
    private function geturlsplice()
    {
        $urlsplice = '?';
        if(false == empty($this->m_pagingdataarray)) {
            //删除当前数组中的page数据
            unset($this->m_pagingdataarray['page']);
            foreach($this->m_pagingdataarray as $pkey=>$pvalue) {
                /* 拼接普通url */
                if((false == empty($pvalue)) && (false == is_array($pvalue))) {
                    $urlsplice .= $pkey.'='.$pvalue.'&';
                }
/* 拼接是数组的url */
                /*if((false == empty($pvalue)) && (true == is_array($pvalue))) {
}*/
            }
            //print_r($this->m_pagingdataarray);
        }
        return $urlsplice;
    }
/*
        返回拼接好的html代码(包括js代码)
    */
    public function getpaginghtmlinfo()
    {
        $urlsplice = $this->geturlsplice();
$pageurl = $this->m_url.$urlsplice.'page=';
        $pageurls = $pageurl.($this->m_page-1);
        $pageurly = $pageurl.($this->m_page+1);
if($this->m_pagecoent > 0) {
            $pagecoent = $this->getpagecoent($pageurl);
        } else {
            $pagecoent = null;
        }
/* 定义分页数据 */
        $html = '';
$home = '首页';
        $previous = '上一页';
        $next = '下一页';
        $end = 'm_totalfraction.'>尾页';
$homes = '首页';
        $previouss = '上一页';
        $nexts = '下一页';
        $ends = '尾页';
/* 当只有一页数据的时候,就没有拼接url地址 */
        if($this->m_totalfraction == 1) {
            $html .= $homes.$previouss.$pagecoent.$nexts.$ends;
        /* 当没有数据的时候,就没有拼接url地址 */
        } elseif($this->m_page == $this->m_totalfraction && $this->m_total == 0) {
            $html .= $homes.$previouss.$pagecoent.$nexts.$ends;
        /* 当为第一页的时候 */
        } elseif($this->m_page == 1) {
            $html .= $homes.$previouss.$pagecoent.$next.$end;
/* 到尾部的时候 */
        } elseif($this->m_page == $this->m_totalfraction  && $this->m_totalfraction > 1) {
            $html .= $home.$previous.$pagecoent.$nexts.$ends;
/* 正常的时候 */
        } else {
                $html .= $home.$previous.$pagecoent.$next.$end;
        }
        $html .= '当前第'.$this->m_page.'页共'.$this->m_totalfraction.'页总有'.$this->m_total.'条数据
';
/* css代码 */
        $css = '';
return $html.$css;
    }
}
//使用方法
/* 调用分页模块 */
        $configuration = array(
            'total' => $studentcount,  //数据总条数
            'traction' => $studentpage,  //每页显示条数
            'pagecoent' => 3,  //分页显示的个数
            'url' => './studentmanagement',  //翻页的url地址
        );
               //$_request : 如果当前查询有其它条件将会自动选择拼接起来
              //$configuration : 配置项
        $pageingobj = new pagingmodel($_request, $configuration);
        $this->assign('pageing', $pageingobj->getpaginghtmlinfo());
ad:真正免费,域名+虚机+企业邮箱=0元
其它类似信息

推荐信息