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 stm32代码移植没反应
  • ¥15 matlab基于pde算法图像修复,为什么只能对示例图像有效
  • ¥100 连续两帧图像高速减法
  • ¥15 组策略中的计算机配置策略无法下发
  • ¥15 如何绘制动力学系统的相图
  • ¥15 对接wps接口实现获取元数据
  • ¥20 给自己本科IT专业毕业的妹m找个实习工作
  • ¥15 用友U8:向一个无法连接的网络尝试了一个套接字操作,如何解决?
  • ¥30 我的代码按理说完成了模型的搭建、训练、验证测试等工作(标签-网络|关键词-变化检测)
  • ¥50 mac mini外接显示器 画质字体模糊