DreamOn Posted March 1, 2011 Share Posted March 1, 2011 Hi All Im trying to get my Paganation to work, well it is working, just not how i want it to work... atm it will list 2 records per page, then it will list the page numbers... First Previous 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 etc Next Last My page numbers show every page, so when i have 100+pages it will show them all. I would like to change my current code to something like the following: 1 2 3 4 5 6 7 8 9 10 - Next 10 Previous 10 - 11 12 13 14 15 16 17 18 19 20 - Next 10 below is my current code... i have only just started to learn PHP (2-3days ago) ive looked at aload of tutorials but still cant get my head around how to do it. My Current Code: if (isset($_GET["page"])) { $page = $_GET["page"]; } else { $page=1; }; $start_from = ($page-1) * 2; $rs_result = @mysql_query("SELECT Count(idinfo) from info WHERE fldName LIKE '". $_GET['run'] . "%'"); $row1 = mysql_fetch_row($rs_result); $total_records = $row1[0]; $total_pages = ceil($total_records / 2); if ($total_pages == 1) {} else {If ($page == 1) {} else{ echo " <a href='index.html?run=". $_GET['run'] . "&page=1'> <<-First</a> "; echo " "; } If ($page == 1) {} else{ $previous = $page-1; echo " <a href='index.html?run=". $_GET['run'] . "&$previous'> <-Previous</a> "; } } for ($i=1; $i<=$total_pages; $i++) { echo "<a href='index.html?run=". $_GET['run'] . "&page=".$i."'>Page ".$i."</a> "; } if ($page == $total_pages) { } else { $previous = $page+1; echo " <a href='index.html?run=". $_GET['run'] . "&page=$previous'> Next-></a> "; If ($page == $total_pages) {} else{ echo " <a href='index.html?run=". $_GET['run'] . "&page=$total_pages'> Last->></a> "; } } echo ("<br> Page $page of $total_pages<br><br>"); } There is probably better ways to code this in, but it works like this so i am happy Any help will be great. Thanks -Dream Quote Link to comment https://forums.phpfreaks.com/topic/229320-paganation/ Share on other sites More sharing options...
chaseman Posted March 1, 2011 Share Posted March 1, 2011 2-3 days ago, and already working with pagination? Do you have previous programming experience or are you a fast learner? lol Anyway, I've started learning PHP 2 month ago, with no previous programming experience. And I've build a great working pagination with the help of this forum. Check out this tutorial on PHPFreaks, if you haven't done already: http://www.phpfreaks.com/tutorial/basic-pagination It is kept simple which is great for learning. It also showcases in that tutorial, how to do what you're trying to accomplish, just look at the part where it's saying how to showcase the 3 previous and next pages. Quote Link to comment https://forums.phpfreaks.com/topic/229320-paganation/#findComment-1181601 Share on other sites More sharing options...
DreamOn Posted March 1, 2011 Author Share Posted March 1, 2011 fast learner i have previous programming experience but only with MS Access VBA. Plus non stop reading and testing does help i will check that link out. Cheers -Dream Quote Link to comment https://forums.phpfreaks.com/topic/229320-paganation/#findComment-1181613 Share on other sites More sharing options...
QuickOldCar Posted March 2, 2011 Share Posted March 2, 2011 I made some pagination that are welcome to use or just get idea's from. Code for them is at the links. http://get.blogdns.com/paginate http://get.blogdns.com/dynaindex/paginate.php Quote Link to comment https://forums.phpfreaks.com/topic/229320-paganation/#findComment-1181708 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.