iPixel Posted April 9, 2007 Share Posted April 9, 2007 Ok long story short ! I've got some regular joe schmoe queries running ... now the totally result of these queries goes well over 2,000 records. Im looking to paginate these in a certain fashion : << Prev 1 2 3 4 5 6 7 8 9 10 Next >> Each # obviously will display the page ! but Prev and Next will jump to either previous 10 or next 10... so if im on page 4 and i hit next ! i dont want to go to page 5 but rather page 11 and display: << Prev 11 12 13 14 15 16 17 18 19 20 Next >> I hope this is doable ! if not please give me a better suggestion, a more effective and/or efficient way to be able to browse through all these records. Link to comment https://forums.phpfreaks.com/topic/46316-help-with-specific-pagination/ Share on other sites More sharing options...
boo_lolly Posted April 9, 2007 Share Posted April 9, 2007 there are many ways to impliment pagination into your search results. you have to decide what you think would be best for your users, and then decide the best way to code it. this is doable. have you searched for tutorials on pagination? have you come up with any code so far? Link to comment https://forums.phpfreaks.com/topic/46316-help-with-specific-pagination/#findComment-225336 Share on other sites More sharing options...
iPixel Posted April 9, 2007 Author Share Posted April 9, 2007 I dont have any code for this yet ... im having a little trouble imagining the logic of how to get this working ! If i can anywhere before someone posts something here ill update the thread. Thanks Link to comment https://forums.phpfreaks.com/topic/46316-help-with-specific-pagination/#findComment-225338 Share on other sites More sharing options...
boo_lolly Posted April 9, 2007 Share Posted April 9, 2007 we all recommend you google it first, always. then, come to the forums to ask questions about things you found. that's generally the best way to get a responsive thread off to a good start. Link to comment https://forums.phpfreaks.com/topic/46316-help-with-specific-pagination/#findComment-225358 Share on other sites More sharing options...
iPixel Posted April 10, 2007 Author Share Posted April 10, 2007 So i googled "php pagination" and look and see phpfreaks.com was on the top of the list... http://www.phpfreaks.com/tutorials/43/0.php So im looking at this pagination code and i like it its nice and clean but with 1 issue ! The Code below, lets say i have the 2000 records, and my limit is lets say 50 per page, im gonna end up with <<PREV 1 2 3 4 5 ..... 35 36 37 38 39 40 NEXT>> and thats the problem with this code, i do not want 40 pages, this database will grow to well over 30,000 records and i dont want to have 1,000 page shown on the pagination, and im not sure how to minimize it to 10's and have the prev and next move to either the previous 10 or the next 10 ! if($page != 1){ $pageprev = $page--; echo("<a href=\"$PHP_SELF&page=$pageprev\">PREV".$limit."</a> "); }else{ echo("PREV".$limit." "); } $numofpages = $totalrows / $limit; for($i = 1; $i <= $numofpages; $i++){ if($i == $page){ echo($i." "); }else{ echo("<a href=\"$PHP_SELF?page=$i\">$i</a> "); } } if(($totalrows % $limit) != 0){ if($i == $page){ echo($i." "); }else{ echo("<a href=\"$PHP_SELF?page=$i\">$i</a> "); } } if(($totalrows - ($limit * $page)) > 0){ $pagenext = $page++; echo("<a href=\"$PHP_SELF?page=$pagenext\">NEXT".$limit."</a>"); }else{ echo("NEXT".$limit); } Thanks for the help ! ~iPixel Link to comment https://forums.phpfreaks.com/topic/46316-help-with-specific-pagination/#findComment-225782 Share on other sites More sharing options...
Asheeown Posted April 10, 2007 Share Posted April 10, 2007 // Build First and Prev links. If on page 1, we won't make links if($page > 1){ $prev = ($page - 1); echo (" <a href=''>First</a> <a href=''>Prev</a> "); } // end if // build the links to the 4 previous and 4 next pages for($i = ($page - 3); $i <= ($page + 3); $i++){ // only make a link if the prev\next is a valid page number if (($i >= 1) && ($i <= $total_pages)) { echo ($page == $i) ? "[$i] " : "<a href=''>$i</a> "; } // end if } // end for // Build Next and Last links. If on last page, we won't make a links if($page < $total_pages){ $next = ($page + 1); echo (" <a href=''>Next</a> <a href=''>Last</a> "); } // end if Now the part I want you to focus on is the middle: for($i = ($page - 3); $i <= ($page + 3); $i++){ That will display only 3 pages each way, for example: First Prev 1 2 3 [4] 5 6 7 Next Last Hope this helped and sorry for the unorganized coding. p.s. links were taken out. Link to comment https://forums.phpfreaks.com/topic/46316-help-with-specific-pagination/#findComment-225846 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.