472,120 Members | 1,443 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,120 software developers and data experts.

How to customize paging links for mysql table

Hi all,

I got code over the net for paging mysql table, it provides Prev pages Next link at the bottom of the table. However, I have a pretty large table to display (average over 400+ rows). Even when I limited the rows to display 30, It still have over 10 page link display between Prev and Next link. Following are code to display the links
echo "<center>";
// Build First & Previous page Link
if($page > 1){
$prev = ($page - 1);
echo "<a href=\"".$admin_file.".php?op=EventsAdmin&page=1\" ><img src=\"images/dl_arrow.gif\" alt=\""._FIRST."\" title=\""._FIRST."\" border=\"0\"></a> ";
echo " <a href=\"".$admin_file.".php?op=EventsAdmin&page=$pr ev\"><img src=\"images/l_arrow.gif\" alt=\""._PREV."\" title=\""._PREV."\" border=\"0\"></a> ";
// for loop to build page links
for($i = 1; $i <= $total_pages; $i++){
if(($page) == $i){
echo "&nbsp;[$i]&nbsp;";
} else {
echo " <a href=\"".$admin_file.".php?op=EventsAdmin&page=$i\ ">&nbsp;$i&nbsp;</a> ";
// Build Next & Last page Link
if($page < $total_pages){
$next = ($page + 1);
echo " <a href=\"".$admin_file.".php?op=EventsAdmin&page=$ne xt\"><img src=\"images/r_arrow.gif\" alt=\""._NEXT."\" title=\""._NEXT."\" border=\"0\"></a> ";
$last = $total_pages;
echo " <a href=\"".$admin_file.".php?op=EventsAdmin&page=$la st\"><img src=\"images/dr_arrow.gif\" alt=\""._LASTPAGE."\" title=\""._LASTPAGE."\" border=\"0\"></a>";

echo "</center>";[/PHP]

What I want to do is limited the total number of page link to 5 and only display plus and minus 2 page over the Current Page but not all the pages links.

I don't want to have something like Page x of xxx between the Prev and Next link

Please help or point me to any reference I could study

Thanks in advance
Oct 28 '07 #1
1 1710
5,058 Expert 4TB

This is essentially just a very basic math problem. You simply need to create a for loop, starting at the current page - 2, running through until you reach the current page + 2.

You would of course have to make sure the first and the last page being printed are actually inside the range of available pages. Making sure it doesn't print pages 0 or belove, or that it doesn't go higher than the total number of pages.

All in all, the math behind this is pretty simple.

If you run into any problems, let us know and we will do our best to help you out.
Nov 11 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

2 posts views Thread by RJN | last post: by
reply views Thread by Ray | last post: by
1 post views Thread by ratnakarp | last post: by
6 posts views Thread by khalidbaloch | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.