php分页,每页限制 [英] php pagination, limit per page

查看:58
本文介绍了php分页,每页限制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都可以通过此代码帮助我,以限制每页的数量,

Anyone can help me with this code to limit number per page,

function PageMain() {
    global $TMPL;

    $text = $_GET['a'];
    $name = urldecode(htmlEntities($_GET['q']));
    // pagination
    $per_page = 10;
    $page_query = mysql_query("SELECT COUNT(genres) from table WHERE genres LIKE '%%$name%'");
    $pages = @ceil(mysql_result($page_query, 0) / $per_page);

    $page = (isset($_GET['page']) AND (int)$_GET['page'] > 0) ? (int)$_GET['page'] : 1;
    $start = ($page - 1) * $per_page;

    $skin = new skin('shared/pagination'); $pagination = '';
    if ($pages >= 1 && $page <= $pages) {   
        for ($x=1; $x<=$pages; $x++) {
            $TMPL['pagination'] = ($x == $page) ? '<a class="active" href="/index.php?a=genre&q='.urlencode($name).'&page='.$x.'">'.$x.'</a> ' : '<a href="/index.php?a=genre&q='.urlencode($name).'&page='.$x.'">'.$x.'</a> ';
                $pagination .= $skin->make();
            }
        }
    $TMPL['pagination'] = $pagination;
}

现在看起来像这张照片:

now looks like on this picture:

我需要用下一页和最后一页做这样的事情:

I need to make something like this, with next and last page:

推荐答案

对于大量页面,请考虑使用对数"分页,请参见此处:

For large numbers of pages, consider using "logarithmic" pagination, see here:

如何对很多页面进行页面导航?对数页面导航

这篇关于php分页,每页限制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆