Is there any way to keep my GET parameters when paginating.
My problem is that I have a few different urls i.e
questions.php?sort=votes&author_id=1&page=3
index.php?sort=answers&style=question&page=4
How in my pagination class am I supposed to create a link to the page with a different page number on it but yet still keep the other parts of the url?
In short, you just parse the URL and then you add the parameter at the end or replace it if it already exists.
This example code requires the PHP HTTP module for
http_build_url
andhttp_build_str
. The later can be replaced withhttp_build_query
and for the first one a PHP userspace implementation exists in case you don't have the module installed.Another alternative is to use the
Net_URL2
package which offers an interface to diverse URL operations:It's more flexible and expressive.