I have a pagination method that is working to a point. If I navigate beyond page 2, or use my Previous or Next button, my current page and total page variables are appended to the URL, resulting in something like this:
http://localhost/project/profile.php?s=0&p=2&s=1&p=2&select_genre=Sci-Fi&select_length=1-25&query=Submit
Notice the extra s and p assignments
$s defines the starting page
$p defines total pages
Is there a way to prevent the values of $s and $p from appending to the URL?
I’m sure the problem is in how I carry the GET values across the pages in the URL below, I’m not sure how to correct it:
if($pages > 1)
{
echo '<br /><p>'; //Add some extra space
$current_page = ($start/$display) + 1;
//If it's not the first page, make a PREV button
if($current_page != 1)
{
echo '<a href=profile.php?s=' . ($start - $display) . '&p=' . $pages . '&' . http_build_query($_GET) . '"> Previous</a> ';
}
//Make all the numbered pages:
for ($i = 1; $i <= $pages; $i++)
{
if($i != $current_page)
{
echo '<a href="profile.php?s=' . (($display * ($i - 1))) . '&p=' . $pages . '&' . http_build_query($_GET) . '">' . $i . '</a>';
}
else {
echo $i . ' ';
}
}//END FOR LOOP
// If it's not the last page, make a Next button:
if ($current_page != $pages)
{
echo '<a href="profile.php?s=' . ($start + $display) . '&p=' . $pages . '&' . http_build_query($_GET) . '"> Next</a>';
}
echo '</p>';
}
Thanks!
Well if $_GET contains s or p you you would end-up with doubling those:
Something like that should work