jfarthing Posted December 2, 2007 Share Posted December 2, 2007 I would love if somebody could show me how to do pagination exactly like they did here, its SOOOO clean! http://thebeattrader.com/buybeats.aspx Quote Link to comment Share on other sites More sharing options...
~n[EO]n~ Posted December 2, 2007 Share Posted December 2, 2007 Everybody will love to see you try it first from here http://www.phpfreaks.com/tutorials/43/0.php Quote Link to comment Share on other sites More sharing options...
jfarthing Posted December 2, 2007 Author Share Posted December 2, 2007 That tutorial is not like what I showed... Quote Link to comment Share on other sites More sharing options...
PHP_PhREEEk Posted December 2, 2007 Share Posted December 2, 2007 Sure it is... getting the pagination is the work of the engine. The actual display is the work of HTML and/or CSS. PhREEEk Quote Link to comment Share on other sites More sharing options...
jfarthing Posted December 2, 2007 Author Share Posted December 2, 2007 No, say I have 1000 pages, the code provided on this site will actually list 1000 pages like 1 2 3 4 5 6 7 8 9...etc....this page anly shows a total of like 10 and scrolls them nicely as you go through. Quote Link to comment Share on other sites More sharing options...
PHP_PhREEEk Posted December 2, 2007 Share Posted December 2, 2007 I repeat, the tutorial shows you far more than enough to accomplish the same look and feel as to the link you posted. Page 4 of the tutorial shows how to arrive at the total number of pages that are available. That's the only number you need to get the rest of the magic. Let's state, in plain English, what the bar is doing on the page you provided. Using the limit number, the first column should show the range of data results for the current page. If our limit is 25, page 1 should display 1 - 25, page 2 should show 26 - 50, etc. Very simple math gets you this display, using limit number as the common denominator. The next column displays an image representing 'back one page' if not on page 1. Can be represented as text with << The next column displays the pagination proper. If on page 1, it should display up to 4 pages ahead (if that many available - use total number of pages to check for this). Clicking on pages 2 - 4 retain a display of 1 - 5, we only remove a hyperlink for the current page. Clicking on page 5 changes the bar, and all pages beyond 5 maintain this new change. - Page 1 link always remains. - A new bar is built with the current page (no link) in the middle, and 2 pages forward and backward from current page. - Tack page one on the front of that new bar. You now have the formula for the display of all pages greater than 4. Tacked on to the end of every bar except the last page is an ellipsis (...) followed by the last page available (simply, total number of pages). The last 2 pages are slightly different. There is a page forward graphic in the last column. Can be represented in text as >> Ok... all this stuff is simply presentation. The math to get the bar presented was provided in the tutorial. It is beyond any tutorial to provide every way possible to pimp out your HTML, that's up to you. By following along the plain English above, you should be able to re-create that bar EXACTLY, and quite easily! Simply define the limit, let PHP discover the total number, and then track the current page. Kindergarten stuff! hehe PhREEEk Quote Link to comment Share on other sites More sharing options...
jfarthing Posted December 11, 2007 Author Share Posted December 11, 2007 Well, I came up with something. Don't know if there is a cleaner, more logical approach... <?php function pages($url,$total_items,$per_page,$current_page) { $total_pages = ceil($total_items / $per_page); $prev_page = ($current_page - 1); $next_page = ($current_page + 1); if($current_page != 1) { $return = ' <a href="'.$url.'?page='.$prev_page.'" title="Previous Page">«</a> '; } $return .= 'Page: '; if($current_page != 1) { $return .= ' <a href="'.$url.'"?page=1" title="First Page">1</a> |'; } else { $return .= ' 1 |'; } if ($current_page < 5) { if ($total_pages < 5) { for ($i=2;$i<=$total_pages;$i++) { if ($i == $current_page) { $return .= ' '.$i.' |'; } else { $return .= ' <a href="'.$url.'?page='.$i.'" title="Page '.$i.'">'.$i.'</a> |'; } } } else { for ($i=2;$i<=5;$i++) { if ($i == $current_page) { $return .= ' '.$i.' |'; } else { $return .= ' <a href="'.$url.'?page='.$i.'" title="Page '.$i.'">'.$i.'</a> |'; } } } if ($current_page < $total_pages) { if ($total_pages > 5) { $return .= ' ... | <a href="'.$url.'?page='.$total_pages.'" title="Last Page">'.$total_pages.'</a> |'; } $return .= ' <a href="'.$url.'?page='.$next_page.'" title="Next Page">»</a> '; } } if (($total_pages > 5) && ($current_page >= 5) && ($current_page < ($total_pages-2))) { for ($i=($current_page-2);$i<=$current_page;$i++) { if ($i == $current_page) { $return .= ' '.$i.' |'; } else { $return .= ' <a href="'.$url.'?page='.$i.'" title="Page '.$i.'">'.$i.'</a> |'; } } for ($i=$current_page+1;$i<=$current_page+2;$i++) { if ($current_page >= $total_pages) { break; } else { $return .= ' <a href="'.$url.'?page='.$i.'" title="Page '.$i.'">'.$i.'</a> |'; } } if ($current_page < $total_pages) { $return .= ' ... | <a href="'.$url.'?page='.$total_pages.'" title="Last Page">'.$total_pages.'</a> | <a href="'.$url.'?page='.$next_page.'" title="Next Page">»</a> '; } } if (($total_pages > 5) && ($current_page == ($total_pages-2))) { for ($i=($current_page-2);$i<=$current_page;$i++) { if ($i == $current_page) { $return .= ' '.$i.' |'; } else { $return .= ' <a href="'.$url.'?page='.$i.'" title="Page '.$i.'">'.$i.'</a> |'; } } for ($i=$current_page+1;$i<=$total_pages;$i++) { if ($current_page >= $total_pages) { break; } else { $return .= ' <a href="'.$url.'?page='.$i.'" title="Page '.$i.'">'.$i.'</a> |'; } } if ($current_page < $total_pages) { $return .= ' <a href="'.$url.'?page='.$next_page.'" title="Next Page">»</a> '; } } if (($total_pages > 5) && ($current_page == ($total_pages-1))) { for ($i=($current_page-3);$i<=$current_page;$i++) { if ($i == $current_page) { $return .= ' '.$i.' |'; } else { $return .= ' <a href="'.$url.'?page='.$i.'" title="Page '.$i.'">'.$i.'</a> |'; } } for ($i=$current_page+1;$i<=$total_pages;$i++) { if ($current_page >= $total_pages) { break; } else { $return .= ' <a href="'.$url.'?page='.$i.'" title="Page '.$i.'">'.$i.'</a> |'; } } if ($current_page < $total_pages) { $return .= ' <a href="'.$url.'?page='.$next_page.'" title="Next Page">»</a> '; } } if (($total_pages > 5) && ($current_page == $total_pages)) { for ($i=($current_page-4);$i<=$current_page;$i++) { if ($i == $current_page) { $return .= ' '.$i.' |'; } else { $return .= ' <a href="'.$url.'?page='.$i.'" title="Page '.$i.'">'.$i.'</a> |'; } } for ($i=$current_page+1;$i<=$total_pages;$i++) { if ($current_page >= $total_pages) { break; } else { $return .= ' <a href="'.$url.'?page='.$i.'" title="Page '.$i.'">'.$i.'</a> |'; } } } return $return; } ?> Quote Link to comment 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.