86Stang Posted January 17, 2008 Share Posted January 17, 2008 I'm wanting to limit the number of page links that result from a search. So, instead of seeing "Prev |1|2|3|4 |5|6|7|8|9|Next" etc., you would like to show only 3 pages in either direction of the current page. I.E. if you're on page 5 you'd see "2|3|4|5|6|7|8". Here's what I have and it displays ALL pages: For($i = 1 ; $i <= $TotalNumberOfPages ; $i++) { If($i == $CurrentPage) { $Nav .= "<B>$i</B>"; } Else { $Nav .= "<A HREF=\"search.php?page=" . $i . "&keywords=" .urlencode($keywords) . "\">$i </A>"; } } teng84, I promise not to edit the code snippet this time! Link to comment https://forums.phpfreaks.com/topic/86558-solved-limiting-search-page-numbers/ Share on other sites More sharing options...
tinker Posted January 17, 2008 Share Posted January 17, 2008 $pos = 55; $start = $pos - 3; if($start<0){ $start = 0; } $end = $pos + 3; if($end>$max){ $end = $max; } For($i = $start ; $i <= $end ; $i++) { ... } Link to comment https://forums.phpfreaks.com/topic/86558-solved-limiting-search-page-numbers/#findComment-442275 Share on other sites More sharing options...
86Stang Posted January 18, 2008 Author Share Posted January 18, 2008 No results. Why $pos = 55? What's significant about the number 55? Would that be causing the blank results? Link to comment https://forums.phpfreaks.com/topic/86558-solved-limiting-search-page-numbers/#findComment-442564 Share on other sites More sharing options...
sasa Posted January 18, 2008 Share Posted January 18, 2008 TRY For($i = $CurrentPage > 3 ? $CurrentPage - 3 : 1; $i <= ($CurrentPage + 3 < $TotalNumberOfPages ? $CurrentPage + 3 : $TotalNumberOfPages) ; $i++) Link to comment https://forums.phpfreaks.com/topic/86558-solved-limiting-search-page-numbers/#findComment-442576 Share on other sites More sharing options...
86Stang Posted January 18, 2008 Author Share Posted January 18, 2008 Works perfect. You're a rockstar sasa!! Link to comment https://forums.phpfreaks.com/topic/86558-solved-limiting-search-page-numbers/#findComment-442578 Share on other sites More sharing options...
86Stang Posted January 18, 2008 Author Share Posted January 18, 2008 This is solved but I have a question -- what do the question marks in that last code snippet do exactly? Link to comment https://forums.phpfreaks.com/topic/86558-solved-limiting-search-page-numbers/#findComment-442580 Share on other sites More sharing options...
sasa Posted January 18, 2008 Share Posted January 18, 2008 $i = $CurrentPage > 3 ? $CurrentPage - 3 : 1; means if($CurrentPage > 3) $i = $CurrentPage - 3; else $i = 1; Link to comment https://forums.phpfreaks.com/topic/86558-solved-limiting-search-page-numbers/#findComment-442701 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.