seanmt Posted January 31, 2009 Share Posted January 31, 2009 I have a simple pagination set up (not the one here but very similar.) The pagination works fine usually. But when I have different variables in the url it doesn't work. Online Example (Page links at the bottom) But if I am on a page like.... http://www.fm-base.co.uk/players.php?pos=dm The page links don't know that pos=dm is set. How do I go about doing this? Here is my current code for the page links... $self = $_SERVER['PHP_SELF']; $nav = ''; for($page = 1; $page <= $maxPage; $page++) { if ($page == $pageNum) { $nav .= " $page "; // no need to create a link to current page } else { $nav .= " <a href=\"$self?page=$page\">$page</a> "; } } if ($pageNum > 1) { $page = $pageNum - 1; $prev = " <a href=\"$self?page=$page\"><</a> "; $first = " <a href=\"$self?page=1\"><<</a> "; } else { $prev = ' '; // we're on page one, don't print previous link $first = ' '; // nor the first page link } if ($pageNum < $maxPage) { $page = $pageNum + 1; $next = " <a href=\"$self?page=$page\">></a> "; $last = " <a href=\"$self?page=$maxPage\">>></a> "; } else { $next = ' '; // we're on the last page, don't print next link $last = ' '; // nor the last page link } // print the navigation link echo $first . $prev . $nav . $next . $last; Quote Link to comment https://forums.phpfreaks.com/topic/143303-solved-pagination-help/ Share on other sites More sharing options...
premiso Posted January 31, 2009 Share Posted January 31, 2009 What exactly are you asking? How to add pos=dm to the pagination links? If so let me know, if not be more specific with examples on what you are asking. Quote Link to comment https://forums.phpfreaks.com/topic/143303-solved-pagination-help/#findComment-751566 Share on other sites More sharing options...
seanmt Posted February 1, 2009 Author Share Posted February 1, 2009 What exactly are you asking? How to add pos=dm to the pagination links? If so let me know, if not be more specific with examples on what you are asking. Sorry I didn't word it as best as I could, it's a bit tricky to explain. But basically yes I need the pos=dm to be added to the pagination links if the user is on players.php?pos=dm so it will look like players.php?page=3&pos=dm if they click on page 3. Another example is if they are on players.php?type=5 then to go onto page 3 it should look like players.php?page=3&type=5 Thanks Quote Link to comment https://forums.phpfreaks.com/topic/143303-solved-pagination-help/#findComment-751968 Share on other sites More sharing options...
premiso Posted February 1, 2009 Share Posted February 1, 2009 What exactly are you asking? How to add pos=dm to the pagination links? If so let me know, if not be more specific with examples on what you are asking. Sorry I didn't word it as best as I could, it's a bit tricky to explain. But basically yes I need the pos=dm to be added to the pagination links if the user is on players.php?pos=dm so it will look like players.php?page=3&pos=dm if they click on page 3. Another example is if they are on players.php?type=5 then to go onto page 3 it should look like players.php?page=3&type=5 Thanks It really is not all that hard to do, as long as you know the different types of get data that can be used, type, and pos are one already. So here is a script that will do that for both: <?php $maxPage = 5; $pageNum = 3; $extra = array(); $extra[] = isset($_GET['type'])?"type=" . $_GET['type']:""; $extra[] = isset($_GET['pos'])?"pos=" . $_GET['pos']:""; foreach ($extra as $key => $ex) if ($ex == "") unset($extra[$key]); $extra = implode("&", $extra); $extra = ($extra != "")?$extra . "&":''; $self = $_SERVER['PHP_SELF'] . "?" . $extra; $nav = ''; for($page = 1; $page <= $maxPage; $page++){ if ($page == $pageNum){ $nav .= " $page "; // no need to create a link to current page }else { $nav .= " <a href=\"{$self}page=$page\">$page</a> "; } } if ($pageNum > 1) { $page = $pageNum - 1; $prev = " <a href=\"{$self}page=$page\"><</a> "; $first = " <a href=\"{$self}page=1\"><<</a> "; }else { $prev = ' '; // we're on page one, don't print previous link $first = ' '; // nor the first page link } if ($pageNum < $maxPage) { $page = $pageNum + 1; $next = " <a href=\"{$self}page=$page\">></a> "; $last = " <a href=\"{$self}page=$maxPage\">>></a> "; } else { $next = ' '; // we're on the last page, don't print next link $last = ' '; // nor the last page link } // print the navigation link echo $first . $prev . $nav . $next . $last; ?> Not the cleanest but it works. Quote Link to comment https://forums.phpfreaks.com/topic/143303-solved-pagination-help/#findComment-752010 Share on other sites More sharing options...
seanmt Posted February 1, 2009 Author Share Posted February 1, 2009 Brilliant. Got it working. Thanks for your help. Quote Link to comment https://forums.phpfreaks.com/topic/143303-solved-pagination-help/#findComment-752246 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.