Código fuente de función que permite agregar links a las páginas siguientes y anteriores de acuerdo a los resultados obtenidos.
Código de paginador PHP
Parametros
$page : Página actual, para pasar las paginas este script toma la variable $_GET["page"] al llamar la funcion se debe pasar la página en la que se encuntra actualmente
$cant : Cantidad de resultados, esto perimte calcular despues la cantidad de páginas por donde sera posible moverse
$toshow: cantidad de resultados que se muestran por páginas con este valor y el anterior se calcula la cantidad de páginas a mostrar
define("PAGESVISIBLE", 11); // constante paginado, páginas visibles por tanda
function getFooterlnk($page, $cant, $toshow)
{
$buffer = "";
$cantToShow = $cant;
if ($toshow != 0) {
$cantToShow = $cant / $toshow;
} $ant = $cantToShow;
$cantToShow = (int) $cantToShow;
if ($cantToShow <
$ant) {
$cantToShow++;
} if (!isset($page) || $page == 0) {
$page = 1;
} $buffer.='<h3><div align="center">';
if ($page > 1) {
$buffer.= '<a target="_blank" rel="nofollow" href="?page=".$page-1."">' . 'anterior' . '</a>';
}
for ($i = 1; $i <= $cantToShow; $i++) {
if ($page > PAGESVISIBLE / 2) {
if ($page >
($cantToShow - PAGESVISIBLE / 2) &&
($i <
$cantToShow - PAGESVISIBLE)) {
continue;
} if ($i <
($page - PAGESVISIBLE / 2) &&
($cantToShow >= ($page + PAGESVISIBLE / 2))) {
continue;
} if ($i >
($page + PAGESVISIBLE / 2)) {
break;
}
} else {
if ($i > PAGESVISIBLE) {
break;
}
} if ($page == $i) {
$buffer.=' <span id="mark">" . $i . "</span>';
} else {
$buffer.= '<a target="_blank" rel="nofollow" href="?page=" . $i . "">" . $i . "</a>';
}
} if ($i <
$cantToShow) {
$buffer.= '<a target="_blank" rel="nofollow" href="?page=".$page+1."">" . "siguiente" . "</a>';
}
$buffer.= "</div></h3>";
return $buffer;
}
