Hướng dẫn php update url parameter

I've implemented pagination system for my website in php, only problem with that is following:
suppose my url at which pagination present is,www.abc.com/search.php?mode=study&query=a,currently its showing 20 results per page,when I use pagination to navigate across results, the url changes to www.abc.com/search.php?mode=study&query=a&page=2,www.abc.com/search.php?mode=study&query=a&page=2&page=3 and www.abc.com/search.php?mode=study&query=a&page=2&page=3&page=4,so the problem which I'm facing is when I navigate across results,every time page variable got appended to the url,which is really annoying.
My code for pagination is.

<?php
function displayPaginationBelow($per_page,$page,$total){

$page_url="http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]&";
$adjacents = "2";
$page = ($page == 0 ? 1 : $page); 
$start = ($page - 1) * $per_page;                              
$prev = $page - 1;                         
$next = $page + 1;
$setLastpage = ceil($total/$per_page);
$lpm1 = $setLastpage - 1;
$setPaginate = "";
if($setLastpage > 1)
{  
    $setPaginate .= "<ul class='setPaginate'>";
    $setPaginate .= "<li class='setPage'>Page $page of $setLastpage</li>";
    if ($setLastpage < 7 + ($adjacents * 2))
    {  
        for ($counter = 1; $counter <= $setLastpage; $counter++)
        {
            if ($counter == $page)
                $setPaginate.= "<li><a class='current_page'>$counter</a></li>";
            elseif (isset($_GET['page'])) {
                unset($_GET['page']);
                $page_url = http_build_query($_GET);
                echo $page_url;
                $setPaginate.= "<li><a href='{$page_url}page=$counter'>$counter</a></li>";
            }
            else
                $setPaginate.= "<li><a href='{$page_url}page=$counter'>$counter</a></li>";                 
        }
    }
    elseif($setLastpage > 5 + ($adjacents * 2))
    {
        if($page < 1 + ($adjacents * 2))    
        {
            for ($counter = 1; $counter < 4 + ($adjacents * 2); $counter++)
            {
                if ($counter == $page)
                    $setPaginate.= "<li><a class='current_page'>$counter</a></li>";
                else
                    $setPaginate.= "<li><a href='{$page_url}page=$counter'>$counter</a></li>";                 
            }
            $setPaginate.= "<li class='dot'>...</li>";
            $setPaginate.= "<li><a href='{$page_url}page=$lpm1'>$lpm1</a></li>";
            $setPaginate.= "<li><a href='{$page_url}page=$setLastpage'>$setLastpage</a></li>";     
        }
        elseif($setLastpage - ($adjacents * 2) > $page && $page > ($adjacents * 2))
        {
            $setPaginate.= "<li><a href='{$page_url}page=1'>1</a></li>";
            $setPaginate.= "<li><a href='{$page_url}page=2'>2</a></li>";
            $setPaginate.= "<li class='dot'>...</li>";
            for ($counter = $page - $adjacents; $counter <= $page + $adjacents; $counter++)
            {
                if ($counter == $page)
                    $setPaginate.= "<li><a class='current_page'>$counter</a></li>";
                else
                    $setPaginate.= "<li><a href='{$page_url}page=$counter'>$counter</a></li>";                 
            }
            $setPaginate.= "<li class='dot'>..</li>";
            $setPaginate.= "<li><a href='{$page_url}page=$lpm1'>$lpm1</a></li>";
            $setPaginate.= "<li><a href='{$page_url}page=$setLastpage'>$setLastpage</a></li>";     
        }
        else
        {
            $setPaginate.= "<li><a href='{$page_url}page=1'>1</a></li>";
            $setPaginate.= "<li><a href='{$page_url}page=2'>2</a></li>";
            $setPaginate.= "<li class='dot'>..</li>";
            for ($counter = $setLastpage - (2 + ($adjacents * 2)); $counter <= $setLastpage; $counter++)
            {
                if ($counter == $page)
                    $setPaginate.= "<li><a class='current_page'>$counter</a></li>";
                else
                    $setPaginate.= "<li><a href='{$page_url}page=$counter'>$counter</a></li>";                 
            }
        }
    }
    if ($page < $counter - 1){
        $setPaginate.= "<li><a href='{$page_url}page=$next'>Next</a></li>";
        $setPaginate.= "<li><a href='{$page_url}page=$setLastpage'>Last</a></li>";
    }else{
        $setPaginate.= "<li><a class='current_page'>Next</a></li>";
        $setPaginate.= "<li><a class='current_page'>Last</a></li>";
    }
    $setPaginate.= "</ul>\n";    
}
return $setPaginate;
}

I know problem is with $page_url variable, need help with this little problem

Tải thêm tài liệu liên quan đến bài viết Hướng dẫn php update url parameter