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
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> ";


}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.