The problem is that when I load page 2 for example the URL becomes:
http://domain.com/index.php?restaurant-id=45¤tpage=2
And that’s fine but when I get to page 3 it becomes:
http://domain.com/index.php?restaurant-id=45¤tpage=2¤tpage=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
You could remove currentpage parameter from
$current_page_urlvariable with regex although it’s ugly.However I’d suggest writing a small function that will generate URLs on the values you pass to it and then you can easily modify any parameter without having to worry about regexes and removing them from the URL. Something like this should be fine.