Alexhoward Posted October 27, 2008 Share Posted October 27, 2008 Good Morning, I have been looking for examples of how to display paging like that at the bottom of the php help page. Where it shows a number of results then "....." then the last page and when you move on it shows "1...11,12,13,14...285" could anyone point me to a good tutorial? i am pulling the results from MySQL Thanks in advance Quote Link to comment https://forums.phpfreaks.com/topic/130252-solved-php-paging-like-that-at-the-bottom-of-the-php-help-page/ Share on other sites More sharing options...
n3ightjay Posted October 27, 2008 Share Posted October 27, 2008 http://www.php-mysql-tutorial.com/php-mysql-paging.php thats a pretty good tutorial ... Quote Link to comment https://forums.phpfreaks.com/topic/130252-solved-php-paging-like-that-at-the-bottom-of-the-php-help-page/#findComment-675490 Share on other sites More sharing options...
Alexhoward Posted October 27, 2008 Author Share Posted October 27, 2008 Excellent, I'll have a read... Quote Link to comment https://forums.phpfreaks.com/topic/130252-solved-php-paging-like-that-at-the-bottom-of-the-php-help-page/#findComment-675494 Share on other sites More sharing options...
Alexhoward Posted October 27, 2008 Author Share Posted October 27, 2008 That's great! however it will show all pages, for the purpose of the site i'm creating that will be fine, as there is not that many results. but how would you display it as it is at thee bottom of the php help page (for example)... cheers Quote Link to comment https://forums.phpfreaks.com/topic/130252-solved-php-paging-like-that-at-the-bottom-of-the-php-help-page/#findComment-675502 Share on other sites More sharing options...
ngreenwood6 Posted October 27, 2008 Share Posted October 27, 2008 can you explain a little more clearly what you are trying to do? Quote Link to comment https://forums.phpfreaks.com/topic/130252-solved-php-paging-like-that-at-the-bottom-of-the-php-help-page/#findComment-675539 Share on other sites More sharing options...
DeanWhitehouse Posted October 27, 2008 Share Posted October 27, 2008 he wants it like 1,2,3 ..... 9,10,11 I believe, so it doesnt show all the page numbers at one time. Quote Link to comment https://forums.phpfreaks.com/topic/130252-solved-php-paging-like-that-at-the-bottom-of-the-php-help-page/#findComment-675543 Share on other sites More sharing options...
ghqwerty Posted October 27, 2008 Share Posted October 27, 2008 i use this formula for my users page $prev_page = $users - 1; echo "<tr><td colspan='3'>"; if($prev_page >= 1){ echo "<b><< <a href=users.php?users=$prev_page>Prev.</a></b>"; //if you are on page 2 or more display a previous link } if($totalpages <= 3){ //this is the pagination link for($i = 1; $i <= $totalpages; $i++){ echo "<a href='users.php?users=$i'> $i </a>| ";//if there are less than 3 pages just show 1|2|3 } }else{ $twobefore = $users-2; $onebefore = $users-1; $oneafter = $users+1; $twoafter = $users+2; //i prefer using a nested version as i understand it easuier you could just as easily use an elseif formula if($twobefore >= 1){ echo "<a href=users.php?users=1> 1 </a>"; echo "<a href=users.php?users=$twobefore> $twobefore </a>";//if you are on page 3 or more show a link to the previous 2 pages if($onebefore >= 1){ echo "<a href=users.php?users=$onebefore> $onebefore </a>";//if you are on page 2 or more show a link to the previous page echo "<a href=users.php?users=$user> $user </a>"; // show the link for the page you are currently on if($oneafter <= $totalpages){ echo "<a href=users.php?users=$oneafter> $oneafter </a>";// if you are more than 1 page off max pages show link to next page if($twoafter <= $totalpages){ echo "<a href=users.php?users=$twoafter> $twoafter </a>";// if you are more than 2 page off max pages show link to the next 2 pages if($twoafter < totalpages){ echo "...<a href=users.php?users=$totalpages> $totalpages </a>";//show a link to the last page } } } } } $next_page = $users + 1; if($next_page <= $totalpages) { echo"<a href=users.php?users=$next_page><b>Next</b></a> <b>>></b>";//next link } } Quote Link to comment https://forums.phpfreaks.com/topic/130252-solved-php-paging-like-that-at-the-bottom-of-the-php-help-page/#findComment-675555 Share on other sites More sharing options...
.josh Posted October 27, 2008 Share Posted October 27, 2008 You aren't really going to find a tutorial that explains how to make the navbar exactly as you want it, as that's a matter of style more than anything, and not really related to pagination principles, anymore than say, making the columns sortable. It all comes down to a loop from 1 to total rows, and throwing in conditions to make it display how you want it to display. Basic Pagination It makes the pagination bar look like this: << < 5 6 7 [8] 9 10 11 > >> the < > are prev/next and the << >> are first/last. All you really have to change is having it echo "...." and 1/$numrows instead of arrows. Quote Link to comment https://forums.phpfreaks.com/topic/130252-solved-php-paging-like-that-at-the-bottom-of-the-php-help-page/#findComment-675574 Share on other sites More sharing options...
Alexhoward Posted November 24, 2008 Author Share Posted November 24, 2008 Excellent! thanks for all your help! Quote Link to comment https://forums.phpfreaks.com/topic/130252-solved-php-paging-like-that-at-the-bottom-of-the-php-help-page/#findComment-697954 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.