Pagination with multiple queries
Posted: Fri Jun 17, 2005 3:39 pm
I am a new php coder, trying to set up my first site with pagination. I used the code posted by nuke at webhostingtalk.com forums (second to last post on the page). I was able to get pagination to work fine, but ran into trouble with the code used to parse the query string. I am trying to break up a list into multpile pages with multiple ways to be ordered.
When used in conjunction with this code to build the links, it produces undesired results.
Every time you click on a new page, it adds a new query to the url, instead of replacing the old one. I've tried some string parsing to remove the old query before it adds the new one, but it doesn't enter the if($pos) statement.
I would simply remove the query string portion of the code, but I also have queries going to order the list in multiple ways which would be lost if I didn't include the query string.
Is there an easier way for me to avoid getting results like this?
Code: Select all
if ( empty($_SERVERї"e;QUERY_STRING"e;]) )
{
$_SERVERї"e;QUERY_STRING"e;] = "e;?"e;;
} else {
$_SERVERї"e;QUERY_STRING"e;] = $_SERVERї"e;QUERY_STRING"e;] . "e;&"e;;
}Code: Select all
echo "e;<a href=\"e;{$_SERVERї"e;PHP_SELF"e;}{$_SERVERї"e;QUERY_STRING"e;}page=$prev\"e;><< Prev</a>&nbsp;"e;;Code: Select all
http://127.0.0.1/taquerias.php?page=2&page=1&page=3&page=4Code: Select all
if ( empty($_SERVERї"e;QUERY_STRING"e;]) )
{
$_SERVERї"e;QUERY_STRING"e;] = "e;?"e;;
}
else
{
$findme = 'page';
$pos = strrchr($_SERVERї'QUERY_STRING'], $findme);
if ($pos === TRUE) {
$_SERVERї"e;QUERY_STRING"e;] = substr_replace($_SERVERї'QUERY_STRING'], '', -6);
}
$_SERVERї"e;QUERY_STRING"e;] = "e;?"e;. $_SERVERї"e;QUERY_STRING"e;] . "e;&"e;;
}Is there an easier way for me to avoid getting results like this?
Code: Select all
http://127.0.0.1/taquerias.php?page=2&page=1&page=3&page=4