EsOne Posted May 4, 2010 Share Posted May 4, 2010 I currently use the following script to make links from page to page on my website. <?php echo "<p id=\"pages\">"; for($i=0;$i<$limit;$i+=15){ echo "| <a href=\"?start=".($i+1)."\">".($i/15+1)."</a> | "; } ?> Now, I am getting so many pages, that management of them is getting difficult. I want to make it where it only shows the previous 5 pages to the current, and the next 5 pages fromt he current. So, if a person was on page 10, It would show ...5 || 6 || 7 || 8 || 9 || 10 || 11 || 12 || 13 || 14 || 15... Keep in mind I am pretty code dumb, as I am just learning. So any help would have to be dumbed down pretty good. To see what links I am talking about in person, the website is: http://dolphinmania.pandaandpenguin.com/dolphinmania Quote Link to comment https://forums.phpfreaks.com/topic/200710-pages/ Share on other sites More sharing options...
Psycho Posted May 4, 2010 Share Posted May 4, 2010 <?php $current_page = 9; $span_pages = 5; $start_page = (($current_page-5) < 1) ? 1 : ($current_page-5); $end_page = (($current_page+5) > $limit) ? $limit : ($current_page+5); for($page=$start_page; $page<=$end_page; $page++) { if($page==$current_page) { echo "| <b>{{$page}}</b> | "; } else { echo "| <a href=\"?start={$page}\">{$page}</a> | "; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/200710-pages/#findComment-1053252 Share on other sites More sharing options...
EsOne Posted May 4, 2010 Author Share Posted May 4, 2010 Thanks. Don't quite work though. With the start= section, each page starts every 15. So, page 2 would be start=16, page 3 would be start=31 That script assumes pages go as start=1 for page 1, and start=2 for page 2. Quote Link to comment https://forums.phpfreaks.com/topic/200710-pages/#findComment-1053259 Share on other sites More sharing options...
EsOne Posted May 4, 2010 Author Share Posted May 4, 2010 Also, I think that code assumed the person would always be on page 9? o_O Quote Link to comment https://forums.phpfreaks.com/topic/200710-pages/#findComment-1053282 Share on other sites More sharing options...
EsOne Posted May 4, 2010 Author Share Posted May 4, 2010 I need it to do what this forums pages does. Exactly that Quote Link to comment https://forums.phpfreaks.com/topic/200710-pages/#findComment-1053332 Share on other sites More sharing options...
Psycho Posted May 5, 2010 Share Posted May 5, 2010 I need it to do what this forums pages does. Exactly that That is not what you requested. You stated you wanted to show the 5 pages before and the 5 pages after the current page. I only hard coded the current page for illustrative purposes. It is your responsibility to define the current page, the max pages (i.e. limit) and the span (which you already stated would be 5, but the code will allow for different values if you wish. This foum uses more complex functionality to include, possibly, the very first and very last pages and ellipses as needed. You did not ask for that, so I did not provide it. Quote Link to comment https://forums.phpfreaks.com/topic/200710-pages/#findComment-1053405 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.