pankirk Posted January 28, 2009 Share Posted January 28, 2009 So I wrote part of this code, and found other parts of it on the net. Basically it's a PHP paging script and it lets me break up my queries into multiple pages. Basically right now all it does is shows the pages at the bottom, and shows a number for every single page it can show. Example: So, basically what I want to do is be able to maybe tone it down a little by maybe only showing only 4 numbers before the current number and 4 after it? And have some sort of "..." and then show the final page number? Anyway I just want to clean this code up a bit. Can anyone help? The ideal result will be something like digg.com's (scroll to the bottom of the page). you can see how they have a "..." and then show a button for the last page... Something like this (say i'm on page 45) [previous] [1] ... 41 42 43 44 [45] 46 47 48 49 ... [143] [next] Do you understand? If not then please ask me questions. I'm not sure how to get this rolling! Thank you so much in advance I appreciate it! $max = 10; $num = $page * $max - $max; $totalpage = ceil($lines / $max) + 1; $page = 1; if ($page > 1) { echo "<a href=\"?action=index&p=".($page-1)."\"><span id=\"paging\">Previous</span></a> \n"; } else if($page <= 1) { echo "<span id=\"paging\">Previous</span> \n"; } for($i = 1; $i < $totalpage; $i++) { if($i == $page) { echo "<span id=\"paging\">$i</span> \n"; } else { echo "<a href=\"?action=index&p=".$i."\"><span id=\"paging\">$i</span></a> \n"; } } if ($page < $totalpage - 1) { echo "<a href=\"?action=index&p=".($page + 1)."\"><span id=\"paging\">Next</span></a>\n"; } else if($page >= $totalpage - 1) { echo "<span id=\"paging\">Next</span>\n"; } Quote Link to comment https://forums.phpfreaks.com/topic/142736-little-php-paging-help/ Share on other sites More sharing options...
dezkit Posted January 28, 2009 Share Posted January 28, 2009 We need some code if you don't mind Quote Link to comment https://forums.phpfreaks.com/topic/142736-little-php-paging-help/#findComment-748222 Share on other sites More sharing options...
pankirk Posted January 28, 2009 Author Share Posted January 28, 2009 Ah yes It seems I forgot to add that... Sorry about that. Quote Link to comment https://forums.phpfreaks.com/topic/142736-little-php-paging-help/#findComment-748226 Share on other sites More sharing options...
sasa Posted January 28, 2009 Share Posted January 28, 2009 $max = 10; $num = $page * $max - $max; $totalpage = ceil($lines / $max) + 1; // $page = 1; $show = 9; $start = (int) max(1, min($page - floor(($show - 1)/2), $totalpage - $show + 1)); $end = min($totalpage, $start + $show - 1); if ($page > 1) { echo "<a href=\"?action=index&p=".($page-1)."\"><span id=\"paging\">Previous</span></a> \n"; } else if($page <= 1) { echo "<span id=\"paging\">Previous</span> \n"; } for($i = $start; $i <= $end; $i++) { if($i == $page) { echo "<span id=\"paging\">$i</span> \n"; } else { echo "<a href=\"?action=index&p=".$i."\"><span id=\"paging\">$i</span></a> \n"; } } if ($page < $totalpage - 1) { echo "<a href=\"?action=index&p=".($page + 1)."\"><span id=\"paging\">Next</span></a>\n"; } else if($page >= $totalpage - 1) { echo "<span id=\"paging\">Next</span>\n"; } Quote Link to comment https://forums.phpfreaks.com/topic/142736-little-php-paging-help/#findComment-748279 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.