Ver Mensaje Individual
  #3 (permalink)  
Antiguo 12/03/2010, 22:34
pilucho
 
Fecha de Ingreso: noviembre-2004
Ubicación: NULL
Mensajes: 653
Antigüedad: 19 años, 5 meses
Puntos: 6
Respuesta: Paginador de archivos

Usa esto, simple y funciona 100%

Código PHP:

<?php 

if (!isset($_GET['pag'])) $pag 1// Por defecto, pagina 1
else
$pag $_GET['pag']; 

$tampag 5;
$reg1 = ($pag-1) * $tampag;
$result mysql_query("SELECT * FROM empleado"); 
$total mysql_num_rows($result);
if (
mysql_num_rows($result)){ 
  echo 
"<table border = '1'> \n"
  echo 
"<tr><td>Item 1</td><td>Item 2</td></tr> \n";
  for (
$i=$reg1$i<min($reg1+$tampag$total); $i++) {
    
mysql_data_seek($result$i);
    
$row mysql_fetch_array($result);
    echo 
"<tr><td>".$row["idempleado"].
      
"</td><td>".$row["nombres"]."</td></tr> \n"
  }
  echo 
"</table> \n"
}
else
  echo 
"_";


function 
paginar($actual$total$por_pagina$enlace$maxpags=0) {
  
$total_paginas ceil($total/$por_pagina);
  
$anterior $actual 1;
  
$posterior $actual 1;
  
$minimo $maxpags max(1$actual-ceil($maxpags/2)): 1;
  
$maximo $maxpags min($total_paginas$actual+floor($maxpags/2)): $total_paginas;
  if (
$actual>1)
    
$texto "<a href=\"$enlace$anterior\">&laquo;</a> ";
  else
    
$texto "<b>&laquo;</b> ";
  if (
$minimo!=1$texto.= "... ";
  for (
$i=$minimo$i<$actual$i++)
    
$texto .= "<a href=\"$enlace$i\">$i</a> ";
  
$texto .= "<b>$actual</b> ";
  for (
$i=$actual+1$i<=$maximo$i++)
    
$texto .= "<a href=\"$enlace$i\">$i</a> ";
  if (
$maximo!=$total_paginas$texto.= "... ";
  if (
$actual<$total_paginas)
    
$texto .= "<a href=\"$enlace$posterior\">&raquo;</a>";
  else
    
$texto .= "<b>&raquo;</b>";
  return 
$texto;
}
echo 
paginar($pag$total$tampag"index.php?pag="); 

?>