Ver Mensaje Individual
  #1 (permalink)  
Antiguo 19/10/2011, 08:31
super_rayo
 
Fecha de Ingreso: abril-2011
Mensajes: 169
Antigüedad: 13 años
Puntos: 4
Exclamación Problema al paginar resultados

He estado probando paginar resultados pero no hay manera... Siempre me sale "(sin resultados)" y no selecciona los datos de la tabla. Supongo que habrá algo mal en el código:

Código PHP:
Ver original
  1. <?
  2.  
  3. include "carpetapremium/config.php";
  4.  
  5.  
  6. $registros = 2;
  7. $pagina = $_GET["pagina"];
  8.  
  9. if (!$pagina) {
  10.     $inicio = 0;
  11.     $pagina = 1;
  12. }
  13. else {
  14.     $inicio = ($pagina - 1) * $registros;
  15. }
  16.  
  17.  
  18. ?>
  19. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  20. <html>
  21. <head>
  22. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  23. <title>Ejemplo</title>
  24. <style>
  25.     body { font-family: arial; font-size:12px}
  26. </style>
  27. </head>
  28.  
  29. <body>
  30.     <?
  31.     $resultados = mysql_query($database, "SELECT id FROM juegos");
  32.     $total_registros = mysql_num_rows($resultados);
  33.     $resultados = mysql_query($database, "SELECT * FROM juegos ORDER BY id DESC LIMIT $inicio, $registros");   
  34.     $total_paginas = ceil($total_registros / $registros);                  
  35.  
  36.     if($total_registros) {
  37.    
  38.         while($articulo = mysql_fetch_array($resultados)) {
  39.             echo "<font color='#666666'>$articulo[juego]</font><br><br><br>";
  40.            
  41.         }
  42.        
  43.     } else {
  44.         echo "<font color='darkgray'>(sin resultados)</font>";
  45.     }
  46.    
  47.     mysql_free_result($resultados);            
  48.    
  49.     if($total_registros) {
  50.        
  51.         echo "<center>";
  52.        
  53.         if(($pagina - 1) > 0) {
  54.             echo "<a href='paginacion.php?pagina=".($pagina-1)."'>< Anterior</a> ";
  55.         }
  56.        
  57.         for ($i=1; $i<=$total_paginas; $i++){
  58.             if ($pagina == $i)
  59.                 echo "<b>".$pagina."</b> ";
  60.             else
  61.                 echo "<a href='paginacion.php?pagina=$i'>$i</a> ";
  62.         }
  63.      
  64.         if(($pagina + 1)<=$total_paginas) {
  65.             echo " <a href='paginacion.php?pagina=".($pagina+1)."'>Siguiente ></a>";
  66.         }
  67.        
  68.         echo "</center>";
  69.        
  70.     }
  71.     ?>
  72. </body>
  73. </html>

Alguien me puede ayudar, MUCHAS GRACIAS por su ayuda.
__________________
MiniMonigotes.com | Juegos flash online gratis - ¡Entra ya!