I have a pagination script with PHP. When page records are some hundreds, the pagination result is too big. How I can limit the page numbers/links?
Example: < 1 | 2 ... 37 | 38 | 39 | 40 | 41 | 42 ... 82 | 83 >
This is my PHP script
<?php
$ppp = 10;
$rows = mysql_num_rows($query);
$nmpages = ceil($rows/$ppp);
// if current page is not 1, draw PREVIOUS link
if ($pg > 1 && $nmpages != 0) {
echo "<a href=\"?pg=".($pg-1)."\"><</a> ";
}
For($i = 1 ; $i <= $nmpages ; $i++) {
If($i == $pg) {
echo "<a href=\"#\" class=\"selected\"><b>".$i."</b></a> ";
} else {
echo "<a href=\"?pg=".$i."\">".$i."</a> ";
}
}
// if current page less than max pages, draw NEXT link
if ($pg < $nmpages && $nmpages != 0) {
echo "<a href=\"?pg=".($pg+1)."\">></a>";
}
?>
Do you have an ideas how I can do this with the specific PHP script that I have?