Respuesta: Paginación Elementos Código PHP: <?php $values=array("1000","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1","1f","1end"); ?>
<?php $num_entradas_totales="".count($values).""; $num_entradas_por_pagina="35"; $num_paginas_totales="".ceil($num_entradas_totales/$num_entradas_por_pagina)."";
$grupos_de_paginacion="5"; $grupos_totales_de_paginacion="".ceil($num_paginas_totales/$grupos_de_paginacion).""; ?>
<?php print "Entradas Totales : ".$num_entradas_totales."<br>"; print "Entradas por Página : ".$num_entradas_por_pagina."<br>"; print "Páginas Totales : ".$num_paginas_totales."<br>"; print "Grupos de Paginacion : ".$grupos_de_paginacion."<br>"; print "Grupos Totales de Paginación : ".$grupos_totales_de_paginacion."<br><br><br>"; ?>
<?
$r="".$_REQUEST['page']."";
if ($r=="" or $r=="0" or $r<0) { $ini_page="0"; $end_page="".$num_entradas_por_pagina.""; } ?>
<? if ($r>0) { $end_page="".($r*$num_entradas_por_pagina).""; $ini_page="".($end_page-$num_entradas_por_pagina).""; }
echo $ini_page; echo $end_page; ?>
<?php for ($i=$ini_page;$i<$end_page;$i++) { print "".$values[$i].""; }
print "<br><br><br>"; ?>
<?php
if ($_REQUEST['page']=="" or $_REQUEST['page']=="0" or $_REQUEST['page']<"0" or $_REQUEST['page']=="1") { $ini="1"; $end="".$grupos_de_paginacion.""; $prev=""; $next="<a href='?page=".($end)."'>Siguiente</a>"; }
if ($_REQUEST['page']>1 && $_REQUEST['page']<$num_paginas_totales) { $ini="".$_REQUEST['page'].""; $end="".($_REQUEST['page']+$grupos_de_paginacion).""; $prev="<a href='?page=".abs($ini-$grupos_de_paginacion)."'>Anterior</a>"; $next="<a href='?page=".($end)."'>Siguiente</a>"; }
if ($_REQUEST['page']>=$num_paginas_totales) { $ini="".($num_paginas_totales-$grupos_de_paginacion).""; $end="".$num_paginas_totales.""; $prev="<a href='?page=".($ini-$grupos_de_paginacion)."'>Anterior</a>"; }
if ($end>=$num_paginas_totales) { $ini="".($num_paginas_totales-$grupos_de_paginacion).""; $end="".$num_paginas_totales.""; $prev="<a href='?page=".($ini-$grupos_de_paginacion)."'>Anterior</a>"; $next="<a href='?page=".($end)."'>Siguiente</a>"; }
if ($ini<0) { $ini="0"; $end="".$grupos_de_paginacion.""; $prev=""; $next="<a href='?page=".($end)."'>Siguiente</a>"; }
print "$prev ";
for ($i=$ini;$i<=$end;$i++) { echo '<a href="?page='.$i.'">'.$i.'</a>'; }
print " $next";
?>
Como me gusta compartir cosas que hago , aquí está mi paginación , se puede poner paginación de valores captados de un archivo plano o paginar entradas que se lean de un directorio como fotos , etc , se puede indicar el numero de elementos agrupados como de elementos a mostrar por cada página cambiando los valores , al contrario ..... de lo que "algunos opinan" o dicen mucha gente , aquí se entra para obtener ideas , de como hacer las cosas ..... no para que le hagan ningún trabajo , seamos un poquito ecúanimes .....
Un saludo , espero que les guste y se está abierto a cualquier modificación y ayuda que mejore el script , un saludo nuevamente |