dhimok Posted July 26, 2007 Share Posted July 26, 2007 Hello everyone. Can u help me with some pagination issue I want to put a pagination on bottom of the page and I have like 100 page numbers or more, so I want to show only 5 page numbers on both sides of the current page, if u know what i mean like Prev .. 8 9 10 11 12 13 14 15 16 17 .. Next when i move to the right or left then i add or subtract one. Here 's what i have so far for ($i = 1; $i <= $numPages; $i++) { echo " "; if ($i == $pageNum) echo "$i"; else echo "<a href=\"?page=$i\">$i</a>"; } thanks Quote Link to comment Share on other sites More sharing options...
dhimok Posted July 26, 2007 Author Share Posted July 26, 2007 Anyone Quote Link to comment Share on other sites More sharing options...
lightningstrike Posted July 26, 2007 Share Posted July 26, 2007 if ($currentpage > 1){ $x = $currentpage - 1; echo "<a href=\"$x\">Prev</a> "; } if ($currentpage > 5){ echo "... " $b = $currentpage - 5; }else{ $b = 1; } for ($i = $b; $i <= $numPages; $i++) { echo " "; if ($i == $pageNum){ echo $i; }elseif(($currentpage+5)>$i){ echo "<a href=\"?page=$i\">$i</a>"; }else{ break; } } if (($currentpage + 5) < $numPages){ echo " ..."; } if ($currentpage!=$numPages){ $x = $currentpage + 1; echo " <a href=\"$x\">Next</a>"; } Maybe something along the lines of this... not the cleanest code but i believe it should work. Made a small edit. Try it out and see if it works. 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.