首页 php教程 PHP源码 php简单分页类|page.class.php

php简单分页类|page.class.php

May 25, 2016 pm 05:04 PM

简单好用的PHP分页类

<?php
/**
 * page.class.php 分页类
 * 日期:2015-04-05
 * http://aowana.sinaapp.com
 */
class page
{
    public static $url;
    public static $page;
    public static $total;
    public static $size;
    public static $number;
    public static $max;
 
    public static $action = array(&#39;previous&#39;, &#39;number&#39;, &#39;next&#39;);
 
    public static function show($url, $page, $total, $size=10, $number=11)
    {
        self::$url = $url;
        self::$page = $page;
        self::$total = $total;
        self::$size = $size;
        self::$number = $number;
        self::$max = ceil($total / $size);
 
        $str = &#39;&#39;;
        foreach (self::$action as $name)
            $str .= self::$name();
        return $str;
    }
 
    public static function first()
    {
        if (self::$page > 2)
        {
            $url = self::url(1);
            return "<li id=\"pbfirst\"><a href=\"{$url}\" title=\"首页\">首页</a></li>";
        }
    }
 
    public static function previous()
    {
        if (self::$page > 1)
        {
            $url = self::url(self::$page - 1);
            return "<li id=\"pbprevious\"><a href=\"{$url}\" title=\"上一页\">上一页</a></li>";
        }
    }
 
    public static function number()
    {
        $str = &#39;&#39;;
        $f = self::$number % 2 ? (self::$number - 1) / 2 : self::$number / 2;
        $s = self::$page - $f;
        $e = self::$page + $f;
 
        if (self::$page < ($f + 1))
        {
            $s = 1;
            $e = self::$number;
            $e = $e > self::$max ? self::$max : $e;
        }
 
        if (self::$page > (self::$max - $f))
        {
            $s = self::$max - self::$number;
            $s = $s < 1 ? 1 : $s;
            $e = self::$max;
        }
 
        for ($i=$s; $i<=$e; $i++)
        {
            $url = self::url($i);
            if ($i == self::$page)
                $str .= "<li><strong>{$i}</strong></li>";
            else
                $str .= "<li><a href=\"{$url}\" title=\"第{$i}页\">{$i}</a></li>";
        }
        return $str;
    }
 
    public static function next()
    {
        if (self::$page < self::$max)
        {
            $url = self::url(self::$page + 1);
            return "<li id=\"pbnext\"><a href=\"{$url}\" title=\"下一页\">下一页</a></li>";
        }
    }
 
    public static function end()
    {
        if ((self::$max - self::$page) > 1)
        {
            $url = self::url(self::$max);
            return "<li id=\"pbend\"><a href=\"{$url}\" title=\"末页\">末页</a></li>";
        }
    }
 
    public static function url($page)
    {
        return str_replace(&#39;{page}&#39;, $page, self::$url);
    }
}
登录后复制

                   


本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn

热AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover

AI Clothes Remover

用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool

Undress AI Tool

免费脱衣服图片

Clothoff.io

Clothoff.io

AI脱衣机

Video Face Swap

Video Face Swap

使用我们完全免费的人工智能换脸工具轻松在任何视频中换脸!

热工具

记事本++7.3.1

记事本++7.3.1

好用且免费的代码编辑器

SublimeText3汉化版

SublimeText3汉化版

中文版,非常好用

禅工作室 13.0.1

禅工作室 13.0.1

功能强大的PHP集成开发环境

Dreamweaver CS6

Dreamweaver CS6

视觉化网页开发工具

SublimeText3 Mac版

SublimeText3 Mac版

神级代码编辑软件(SublimeText3)