Ver Mensaje Individual
  #4 (permalink)  
Antiguo 25/12/2008, 21:07
esaenz22
(Desactivado)
 
Fecha de Ingreso: abril-2008
Mensajes: 787
Antigüedad: 16 años, 1 mes
Puntos: 7
Respuesta: paginacion de resultados

hola pgmg24. para k no te compliques con tu codigo de paginacion, te dare un codigo mas corto del que tu tienes. asi ahorras lineas de codigo.

Código PHP:

<?php

    $conexion
=mysql_connect("localhost","tu-usuario","tu-clave") or die("Error de conexion.");
    
mysql_select_db("tu-bd",$conexion);
  
    
$numregistros 5;
    
    if (!
$pagina) { 
        
$inicio 0
        
$pagina 1
    } 
    else { 
        
$inicio = ($pagina 1) * $numregistros
    } 
  
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Paginacion en php</title>
</head>

<body>
<?php
    
    $resultados 
"SELECT * FROM tu_tabla";
    
$total mysql_query($resultados) or die(mysql_error());
    
$total_registros mysql_num_rows($total); 

    
$alumnos "SELECT * FROM tu_tabla limit $inicio, $numregistros";
    
$resultado_alumnos mysql_query($alumnos) or die(mysql_error());
    
$total_paginas ceil($total_registros $numregistros); 
    
    
$impresos=0;

?>
<table width="350" border="0" cellpadding="2" cellspacing="1">
  <tr>
    <td>Codigo</td>
    <td>Apellido pat</td>
    <td>Apellido mat;</td>
    <td>Nombres</td>
  </tr>
<?php
    
while ($reg=mysql_fetch_array($resultado_alumnos)){
?>
  <tr>
    <td><?=$reg['alu_cod']; ?></td>
    <td><?=$reg['alu_ape']; ?></td>
    <td><?=$reg['alu_mat']; ?></td>
    <td><?=$reg['alu_nom']; ?></td>
  </tr>
<?php
    $impresos
++;
    }
?>
</table>
<?php

    mysql_close
($conexion);

    if(
$total_registros) {
        
        if((
$pagina 1) > 0) {
            echo 
"<a href='paginacion.php?pagina=".($pagina-1)."'>< Anterior</a> ";
        }
        
        for (
$i=1$i<=$total_paginas$i++){ 
            if (
$pagina == $i) {
                echo 
"<b>".$pagina."</b> "
            } else {
                echo 
"<a href='paginacion.php?pagina=$i'>$i</a> "
            }    
        }
      
        if((
$pagina 1)<=$total_paginas) {
            echo 
" <a href='paginacion.php?pagina=".($pagina+1)."'>Siguiente ></a>";
        }
        
    }
    
?>

</body>
</html>
suerte.