Home > php教程 > php手册 > 一个防google分页的实例

一个防google分页的实例

WBOY
Release: 2016-06-06 20:01:12
Original
887 people have browsed it

/// param name="total"总记录数/param /// param name="per"每页记录数/param /// param name="page"当前页数/param /// param name="query_string"Url参数/param /// 返回一个带HTML代码的分页样式(字符串) private string Pagination(int total, int pe

    /// 总记录数
    /// 每页记录数
    /// 当前页数
    /// Url参数
    /// 返回一个带HTML代码的分页样式(字符串)
    private string Pagination(int total, int per, int page, string query_string)
    {
        int allpage = 0;
        int next = 0;
        int pre = 0;
        int startcount = 0;
        int endcount = 0;
        string pagestr = "";

        if (page         //计算总页数
        if (per != 0)
        {
            allpage = (total / per);
            allpage = ((total % per) != 0 ? allpage + 1 : allpage);
            allpage = (allpage == 0 ? 1 : allpage);
        }
        next = page + 1;
        pre = page - 1;
        startcount = (page + 5) > allpage ? allpage - 9 : page - 4;//中间页起始序号
        //中间页终止序号
        endcount = page         if (startcount         if (allpage         pagestr = "共" + allpage + "页/第" + page + "页   ";


        //中间页处理,这个增加时间复杂度,减小空间复杂度
        for (int i = startcount; i         {
            pagestr += page == i ? "  " + i + "" : "  " + i + "";
        }

        return pagestr;
    }

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template