Jump to content

Making Pagination Work with GET in URL?


chaseman

Recommended Posts

I'm using the PHP Freaks pagination tutorial.

 

Till now the pagination function works very great, except on pages where I use GET in the URL.

 

When I use the pagination navigation links on a profile page like this:

 

domain.com/profile.php?user=konopkov

 

then the URL becomes to this:

 

domain.com/profile.php?current_page=2

 

And the profile won't show up anymore.

 

So my question is how can I achieve it so the pagination navigation links will still work even with URL's which use GET?

 

 

Here's an example of the pagination links section:

 

// echo forward link for next page
echo " <a href='{$_SERVER['PHP_SELF']}?current_page=$next_page'>></a> ";
// echo forward link for last page
echo " <a href='{$_SERVER['PHP_SELF']}?current_page=$total_pages'>>></a> ";

 

 

Thank you.

Link to comment
https://forums.phpfreaks.com/topic/228970-making-pagination-work-with-get-in-url/
Share on other sites

This is how I solved it:

 


$url = $_SERVER['PHP_SELF'];
$profile = "/directory/profile.php";
$user_name_get = $_GET['user'];

if ($url == $profile) {

// echo forward link for next page
echo " <a href='{$_SERVER['PHP_SELF']}?user=$user_name_get&current_page=$next_page'>></a> ";
// echo forward link for last page
echo " <a href='{$_SERVER['PHP_SELF']}?user=$user_name_get&current_page=$total_pages'>>></a> ";

} else {

// echo forward link for next page
echo " <a href='{$_SERVER['PHP_SELF']}?current_page=$next_page'>></a> ";
// echo forward link for last page
echo " <a href='{$_SERVER['PHP_SELF']}?current_page=$total_pages'>>></a> ";


}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.