Generic pagination function.
This example looks like this on a large db:
<< Previous 1 2 3 4 5 6 7 8 9 ... 822 823 Next >>
or
<< Previous 1 2 ... 815 816 817 818 819 820 821 822 823 Next >>
or
<< Previous 1 2 ... 812 813 814 815 816 817 818 ... 822 823 Next >>
enjoy...
1)
{
$pagination .= "";
//previous button
if ($p > 1)
$pagination.= "
<< Previous ";
else
$pagination.= "
<< Previous ";
if ($totalposts < 7 + ($adjacents * 2)){
for ($counter = 1; $counter <= $totalposts; $counter++){
if ($counter == $p)
$pagination.= "
$counter";
else
$pagination.= "
$counter ";}
}elseif($totalposts > 5 + ($adjacents * 2)){
if($p < 1 + ($adjacents * 2)){
for ($counter = 1; $counter < 4 + ($adjacents * 2); $counter++){
if ($counter == $p)
$pagination.= "
$counter ";
else
$pagination.= "
$counter ";
}
$pagination.= " ... ";
$pagination.= "
$lpm1 ";
$pagination.= "
$totalposts ";
}
//in middle; hide some front and some back
elseif($totalposts - ($adjacents * 2) > $p && $p > ($adjacents * 2)){
$pagination.= "
1 ";
$pagination.= "
2 ";
$pagination.= " ... ";
for ($counter = $p - $adjacents; $counter <= $p + $adjacents; $counter++){
if ($counter == $p)
$pagination.= "
$counter ";
else
$pagination.= "
$counter ";
}
$pagination.= " ... ";
$pagination.= "
$lpm1 ";
$pagination.= "
$totalposts ";
}else{
$pagination.= "
1 ";
$pagination.= "
2 ";
$pagination.= " ... ";
for ($counter = $totalposts - (2 + ($adjacents * 2)); $counter <= $totalposts; $counter++){
if ($counter == $p)
$pagination.= "
$counter ";
else
$pagination.= "
$counter ";
}
}
}
if ($p < $counter - 1)
$pagination.= "
Next >>";
else
$pagination.= "
Next >>";
$pagination.= "\n";
}
return $pagination;
}
?>