A problem of a repeated parameter in the pagination links?

Posted by myaccount on Stack Overflow See other posts from Stack Overflow or by myaccount
Published on 2010-06-05T16:56:58Z Indexed on 2010/06/05 17:02 UTC
Read the original article Hit count: 162

Filed under:
|
|

The problem is that when I load page 2 for example the URL becomes:

http://domain.com/index.php?restaurant-id=45&currentpage=2

And that's fine but when I get to page 3 it becomes:

http://domain.com/index.php?restaurant-id=45&currentpage=2&currentpage=3

And so on, it adds one more currentpage parameter everytime a new page is loaded from the pagination links!

I wonder how this problem can be fixed?

Here's some of the pagination function's code

 /******  build the pagination links ******/
// Getting current page URL with its parameters
$current_page_url = ($_SERVER["PHP_SELF"].(isset($_SERVER["QUERY_STRING"])?"?".htmlentities($_SERVER["QUERY_STRING"]):""));
// Determine which sign to use (? or &) before the (currentpage=xx) parameter
$sign = preg_match('/\?/', $current_page_url) ? '&' : '?';

$pagination_links = '';
// if not on page 1, don't show back links
if ($currentpage > 1) {
   // show << link to go back to page 1
   $pagination_links .= " <a href='{$current_page_url}{$sign}currentpage=1'>First page</a> ";
   // get previous page num
   $prevpage = $currentpage - 1;
   // show < link to go back 1 page
   $pagination_links .= " <a href='{$current_page_url}{$sign}currentpage=$prevpage'>previous</a> ";
}
else
{
    $pagination_links .= "? ?"; 
}// end if 

© Stack Overflow or respective owner

Related posts about php

Related posts about parameters