scooter41 Posted October 16, 2007 Share Posted October 16, 2007 Hi There.... I have a user based system I am creating, that has 97k users, so as you can imagine for page numbering I simply cant list every page number I have a script that goes either side of the current page i.e if current page is 30, then page numbering starts from 20 and goes to 40 for example. To do this I am using: for($i = 1; $i <= $total_pages; $i++){ if(($page) == $i){ $pagelinks.= " |<span class='currPage'> $i </span>| "; } else { if (($i < $page+10 && $i > $page-10 )){ $pagelinks.="<a href=\"?page=$i$urlvars2\">$i</a> "; } } } But my question is, is there anyway for the values under 10, for example, page 3 that only 10 page links are created instead of the regular 20, so it looks a bit inconsistent with the other pages. Is there a neat and tidy way to format that if statement to say if current page is under 10, bump up the top end limiter? Quote Link to comment https://forums.phpfreaks.com/topic/73431-solved-page-numbering-10-either-side-of-the-current-page/ Share on other sites More sharing options...
Barand Posted October 16, 2007 Share Posted October 16, 2007 try this. It will also take care of the other end of the range when you get near the last page. <?php $total_pages = 100; $page = isset($_GET['page']) ? $_GET['page'] : 1; // set from form for testing if ($page < 1) $page = 1; if ($page > $total_pages) $page = $total_pages; if ($page < 10) { $startnum = 1; $endnum = min(20, $total_pages) ; } elseif ($page > $total_pages-10) { $startnum = max(1, $total_pages - 19); $endnum = min($page + 10, $total_pages); } else { $startnum = max(1, $page - 9); $endnum = min($page + 10, $total_pages); } for($i = $startnum; $i <= $endnum; $i++){ if ($page == $i){ $pagelinks.= " |<span class='currPage'> $i </span>| "; } else { $pagelinks.="<a href=\"?page=$i$urlvars2\">$i</a> "; } } echo $pagelinks; ?> <form> <input type="text" name="page" size="5"> <input type="submit" name="sub" value="Submit"> </form> Quote Link to comment https://forums.phpfreaks.com/topic/73431-solved-page-numbering-10-either-side-of-the-current-page/#findComment-370516 Share on other sites More sharing options...
scooter41 Posted October 16, 2007 Author Share Posted October 16, 2007 Thats perfect! Works really great....... thanks Quote Link to comment https://forums.phpfreaks.com/topic/73431-solved-page-numbering-10-either-side-of-the-current-page/#findComment-370525 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.