dongtang8678 2013-08-05 02:32
浏览 22
已采纳

使用哈希和参数分页不起作用

I have page with a URL like this:

http://***.com/profile/username#profile_favs

With my pagination it looks like this:

http://***.com/profile/username?s=0&p=1#profile_favs

The last example doesn't work.

Basically my pagination-function looks like this:

function Pagination($pages, $start, $display, $link_url="", $anchor="") {

echo '<div id="pagination">';

    $current_page = ($start / $display) + 1;

    $paginator_num = 5;
    $pages_display = 10;

    if ($current_page > $pages - $paginator_num) {
        $paginator_num = $pages_display - ($pages - $current_page);
    } elseif ($current_page < $paginator_num + 1) {
        $paginator_num = $pages_display - $current_page;
    } else {
        $paginator_num = 5;
    }

    $min = max($current_page - $paginator_num, 1); 
    $max = min($current_page + $paginator_num, $pages); 

    for ($i = $min; $i <= $max; $i++) {
        if ($i != $current_page) {
            echo '<div class="pagination_link">';
                echo '<a href="/'.$link_url.'?s=' . (($display * ($i - 1))) . '&p=' . $pages . $anchor.'">' . $i . '</a>';
            echo '</div>';

        } else {
            echo '<div id="pagination_active" class="pagination_link">';
                echo $i . ' ';
            echo '</div>';
        }
    }       

    echo '</div>';
}

And this is the part that calculates the pages (this part gets included right before my pagination-function):

<?php
$display = $display_num;

if (isset($_GET['p']) && is_numeric ($_GET['p'])) {
    $pages = $_GET['p'];

} else {
    $total_results = $qr_num;

    if ($total_results > $display) {
        $pages = ceil ($total_results / $display);
    } else {
        $pages = 1;

    }
}

if (isset($_GET['s']) && is_numeric ($_GET['s'])) {

    $start = $_GET['s'];

} else {
    $start = 0;
}



?>

Now my question is: Is there any workaround possible to get that pagination working with a URL mentioned above:

http://***.com/profile/username?s=0&p=1#profile_favs

Actually I'd prefer a solution without GET-parameters. Any help, please?

  • 写回答

1条回答 默认 最新

  • dongzhang1839 2013-08-05 02:48
    关注
    1. You could use an AJAX call with the XMPHttpRequest Object to fetch it without the get parameters.

    2. Another thing you could do (if you are using Apache) is to look at mod_rewrite for urls.

    Hope that helps :)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 在获取boss直聘的聊天的时候只能获取到前40条聊天数据
  • ¥20 关于URL获取的参数,无法执行二选一查询
  • ¥15 液位控制,当液位超过高限时常开触点59闭合,直到液位低于低限时,断开
  • ¥15 marlin编译错误,如何解决?
  • ¥15 有偿四位数,节约算法和扫描算法
  • ¥15 VUE项目怎么运行,系统打不开
  • ¥50 pointpillars等目标检测算法怎么融合注意力机制
  • ¥20 Vs code Mac系统 PHP Debug调试环境配置
  • ¥60 大一项目课,微信小程序
  • ¥15 求视频摘要youtube和ovp数据集