douniewei6346 2014-09-29 15:52
浏览 9
已采纳

分页问题导致PHP

I'm developing a search function for a web, until now works like a charm but i have an issue with the pagination. I have the following URL format:

https://www.server.com/search?w=something&re=34&page=1

I need to change specifically the page number in the URL, i have a function that retrieves the full URL but is not useful because when i click on the page number it does this:

https://www.server.com/search?w=something&re=34&page=1&page=2&page=3

I need to replace specifically the page= to the number i want. How can i achieve this?

The full code of the function is this:

function PAGINAR($page,$totalPages){
        global $link;

        $nextpage= $page + 1;
        $prevpage= $page - 1;

        $paginado = '<ul id="pagination-digg">';

        if ($page == 1){
            $paginado .= '<li class="previous-off">&laquo; Previous</li>';
        }else{
            $paginado .= '<li class="previous"><a href="'.getUrl().'&page='.$prevpage.'">&laquo; Previous</a></li>';
        }

        for($i = max(1, $page - 5); $i <= min($page + 5, $totalPages); $i++){
            if ($page == $i){
                $paginado .= '<li class="active">'.$i.'</li>';
            }else{
                $paginado .= '<li><a href="'.getUrl().'&page='.$i.'">'.$i.'</a></li>';
            }
        }

        if($totalPages > $page ){      
               $paginado .= '<li class="next"><a href="'.getUrl().'&page='.$nextpage.'">Next &raquo;</a></li>';
            }else{
                $paginado .= '<li class="next-off">Next &raquo;</li>';
            }

        $paginado .= '</ul>';

        return $paginado;
    }

And this retrieves the URL

function getUrl() {
  $url  = @( $_SERVER["HTTPS"] != 'on' ) ? 'http://'.$_SERVER["SERVER_NAME"] :  'https://'.$_SERVER["SERVER_NAME"];
  $url .= $_SERVER["REQUEST_URI"];
  return $url;
}

Thanks in advance

  • 写回答

2条回答 默认 最新

  • doumi5223 2014-09-29 16:10
    关注

    Here is one example that might help you:

    $url = 'https://www.server.com/search?w=something&re=34&page=1';
    
    parse_str( parse_url( $url, PHP_URL_QUERY ), $params );
    $params['page'] = 2;
    
    echo http_build_query( $params );   // outputs: w=something&re=34&page=2
    

    parse_url
    parse_str
    http_build_query

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测