【问题标题】:php pagination, limit per pagephp分页,每页限制
【发布时间】:2012-06-25 12:05:51
【问题描述】:

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

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;
}

现在看起来像这张照片:

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

【问题讨论】:

标签: php pagination


【解决方案1】:

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

How to do page navigation for many, many pages? Logarithmic page navigation

【讨论】:

    猜你喜欢
    • 2018-04-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-02-21
    • 1970-01-01
    • 1970-01-01
    • 2019-10-23
    相关资源
    最近更新 更多