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! Quote Link to comment 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++) { ... } Quote Link to comment 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? Quote Link to comment 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++) Quote Link to comment 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!! Quote Link to comment 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? Quote Link to comment 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; 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.