Ver Mensaje Individual
  #3 (permalink)  
Antiguo 03/10/2009, 12:48
Nisrokh
 
Fecha de Ingreso: septiembre-2009
Ubicación: Neuquén
Mensajes: 142
Antigüedad: 14 años, 7 meses
Puntos: 12
Respuesta: Paginacion no me cambia el valor de la primera fila

Yo de casualidad justo estaba probando hacer uno ya que nunca habia hecoh xD Te lo dejo para que lo veas, cambias las queries y el fetch segun tus necesidaes y te va a funionar, tiene hasta el CSS armado jeje saludos!


Si ves esto en el codigo: & #37 ; (sin espacios) reemplazalo por esto %

Código php:
Ver original
  1. <html>
  2. <head>
  3.     <title>MySQL Test</title>
  4.     <style type="text/css">
  5.         <!--
  6.         body
  7.         {
  8.             font-family: 'Lucida Grande', 'Lucida Sans', 'Lucida Sans Unicode', 'Verdana', sans-serif;
  9.             font-size: 12px;
  10.         }
  11.        
  12.         .page,
  13.         .page:active,
  14.         .page:link,
  15.         .page:visited
  16.         {
  17.             background: #F0F0F0;
  18.             border: 1px solid #CCC;
  19.             margin: 0 2px 0 2px;
  20.             padding: 4px 8px 4px 8px;
  21.             text-decoration: none;
  22.             color: #990000;
  23.             display: block;
  24.             float: left;
  25.         }
  26.        
  27.         .page:hover
  28.         {
  29.             background: #FFF;
  30.             border: 1px solid #AAA;
  31.         }
  32.        
  33.         .active
  34.         {
  35.             background: #FFF;
  36.             border: 1px solid #AAA;
  37.             margin-top: -2px;
  38.             padding: 6px 10px 6px 10px;
  39.             font-weight: bold;
  40.             color: #161616;
  41.         }
  42.        
  43.         .page.below,
  44.         .page.above
  45.         {
  46.             margin-top: -1px;
  47.             padding: 5px 9px 5px 9px;
  48.         }
  49.         -->
  50.     </style>
  51. </head>
  52. <body>
  53. <?php
  54.  
  55. $link = mysql_connect('localhost','root','',true);
  56. $connected = mysql_select_db('test',$link) ? true : false;
  57.  
  58. // Get page
  59. $page = $_GET['page'] ? $_GET['page'] : 1;
  60.  
  61. // Results per page
  62. $rpp = 2;
  63.  
  64. // Get total news
  65. $query = "SELECT * FROM news";
  66. $result = mysql_query($query,$link);
  67. $total_news = mysql_num_rows($result);
  68.  
  69. if ($total_news < 1) return print 'No results found. ';
  70.  
  71. if (($total_news % $rpp) != 0)
  72. {
  73.     $last_page_results = $total_news % $rpp;
  74.     $total_pages = ($total_news - $last_page_results) / $rpp + 1;
  75. }
  76. else $total_pages = $total_news / $rpp;
  77.  
  78. $pages = array();
  79. $cp = 0;
  80.  
  81. for ($i = 1; $i <= $total_pages; $i++)
  82. {
  83.     if ($last_page_results and $i == $total_pages)
  84.     {
  85.         $pages[$i] = $cp. ','. $last_page_results;
  86.         break;
  87.     }
  88.     $pages[$i] = $cp. ','. $rpp;
  89.     $cp+= $rpp;
  90. }
  91.  
  92. if ($page > $total_pages) print 'No more pages after page '. $total_pages. '! ';
  93. else
  94. {
  95.     $_query = "SELECT id,title,content,date FROM news LIMIT ". $pages[$page];
  96.    
  97.     $_result = mysql_query($_query,$link);
  98.    
  99.     while ($row = mysql_fetch_assoc($_result))
  100.     {
  101.         print '<h4>' .$row['title']. ' (' .$row['date']. ')</h4>'."\r\n";
  102.         print '<p>' .$row['content']. '</p>'."\r\n";
  103.     }
  104.    
  105.     if ($total_pages > 1) {
  106.        
  107.         $back = ($page == 1) ? '' : ('<a href="?page=' .($page - 1). '" class="page">&laquo; Anterior</a>');
  108.         $first = ($page == 1 or $page == 2) ? '' : ('<a href="?page=1" title="Go to first page..." class="page">...</a>');
  109.         $below = ($page == 1) ? '' : ('<a href="?page=' .($page - 1). '" class="page below">' .($page - 1). '</a>');
  110.         $current = '<span class="page active">' .$page. '</span>';
  111.         $above = ($page == $total_pages) ? '' : ('<a href="?page=' .($page + 1). '" class="page above">' .($page + 1). '</a>');
  112.         $last = ($page == ($total_pages - 1) or $page == $total_pages) ? '' : ('<a href="?page=' .$total_pages. '" title="Go to last page..." class="page">...</a>');
  113.         $next = ($page == $total_pages) ? '' : ('<a href="?page=' .($page + 1). '" class="page">Siguiente &raquo;</a>');
  114.        
  115.         print $back.$first.$below.$current.$above.$last.$next;
  116.     }
  117. }
  118.  
  119. ?>
  120. </body>
  121. </html>

Última edición por Nisrokh; 03/10/2009 a las 12:54