wrathican Posted August 10, 2008 Share Posted August 10, 2008 hey guys i have an image gallery and im using pagination to to split it up into chunks. its a very simple pagination and it works perfectly fine. the only problem i have is that im using some GET vars to control what i get form the database and when browsing through multiple pages my url starts to look like this: /gallery.php?func=viewal&alid=4&page=2&page=1&page=2 the bold bits being the problem im using the REQUEST_URI part of the $_SERVER array. any ideas how i could fix this? code (im using htmlspecialchars so that the page is standards compliant): <?php $server = htmlspecialchars($_SERVER['REQUEST_URI']); if ($page == 1) { echo " First Prev "; } else { echo " <a href='".$server."&page=1'>First</a> "; $prevpage = $page-1; echo " <a href='".$server."&page=$prevpage'>Prev</a> "; } echo " ( Page $page of $lastPage ) "; if ($page == $lastPage) { echo " Next Last "; } else { $nextpage = $page+1; echo " <a href='".$server."&page=$nextpage'>Next</a> "; echo " <a href='".$server."&page=$lastPage'>Last</a> "; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/119022-solved-simple-pagination/ Share on other sites More sharing options...
wildteen88 Posted August 10, 2008 Share Posted August 10, 2008 Problem is with the use of REQUEST_URI as it includes the query string. So every time you click a link it is always going to add &page=X to your url. What I'd do is dynamically build the url. Like so $server = $_SERVER["SCRIPT_NAME"]; // check if the page variable exits if(isset($_GET['page'])) { $page = $_GET['page']; // remove the page from the $_GET array unset($_GET['page']); } // no we'll dynamically build the query string $server .= '?'. http_build_query($_GET); echo $server; Quote Link to comment https://forums.phpfreaks.com/topic/119022-solved-simple-pagination/#findComment-612880 Share on other sites More sharing options...
wrathican Posted August 10, 2008 Author Share Posted August 10, 2008 man, i love you guys. thanks so much!!! Quote Link to comment https://forums.phpfreaks.com/topic/119022-solved-simple-pagination/#findComment-612902 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.