I have been using this for years, problem is, I get a million page links
at the bottom, I have been trying to add stages like 123...789 but cannot
get it to work. I did find another pagination script that does
that but I would rather stay with this one if possible. anyone see a quick edit
not requiring a rewrite or anything complex.

// show $range pages on either side of current page. if this includes page

// 1, don't show "First". if this includes last page, don't show "Last"

// show back links |< and < unless at page 1

if ($curpg > 1) {

if ($curpg - $range > 1) { // wouldn't show page 1 in range

// show << link to go back to page 1

echo "<a href='{$_SERVER['PHP_SELF']}?page=1'>|&lsaquo;</a> ";

}

// get previous page num

$prevpage = $curpg - 1;

// show < link to go back 1 page

echo "<a href='{$_SERVER['PHP_SELF']}?page=$prevpage'>&lsaquo;</a> ";

}

// loop to show links to range of pages around current page

// if previous page <, there is a space after it

for ($x = $curpg - $range;

$x < $curpg + $range + 1;

$x++) {

// if it's a valid page number (not < 1 or > last page)...

if ($x > 0 && $x <= $maxpg) {

// if we're on current page, not a link...

if ($x == $curpg) {

// 'highlight' it but don't make a link

echo "[<b>$x</b>] ";

} else {

// if not current page, make it a link

echo "<a href='{$_SERVER['PHP_SELF']}?page=$x'>$x</a> ";

}

}

}

// if not on last page, show forward > and last page >| links

if ($curpg < $maxpg) {

// get next page

$nextpage = $curpg + 1;

// echo forward link for next page

echo "<a href='{$_SERVER['PHP_SELF']}?page=$nextpage'>&rsaquo;</a> ";

// echo forward link for lastpage, unless last page already showing

if ($curpg + $range < $maxpg) {

echo " <a href='{$_SERVER['PHP_SELF']}?page=$maxpg'>&rsaquo;|</a>";

}

}

//echo "</span>";

/****** end build pagination links ******/

} // end pag_links()

and then to show it just do this somewhere on your page

PHP Code:

<?php
if(mysql_num_rows($rs)>0){
pag_links();
} ?>

10-16-2012, 06:01 PM

sonny

Thanks I will try it, I scraped that code above I posted
its a shame because it worked great but left a ton of page
links that grow after a a while. I Posted that here because I
thought it might be a line or two edit but see it is too complex
to save.

I did visit the site I found it at, http://www.evolt.org/node/19340
and read the old comments and did see some edits to manage all
those page links, but none work I tried them, on page 1 and 2,
they leave out next links and cause bad links.