Tema: Paginador
Ver Mensaje Individual
  #6 (permalink)  
Antiguo 28/07/2011, 17:28
Curda
 
Fecha de Ingreso: septiembre-2009
Ubicación: Queretaro
Mensajes: 51
Antigüedad: 14 años, 7 meses
Puntos: 2
Respuesta: Paginador

bueno este implemento con mi sistema tengo algo de prisa hay q depurar el código y q esta adaptado a mi web pero espero q sea aporte.
no he leido ningún post, entonces no se si ya lo solucionaron solo leí el titulo y estoy posteando, una disculpa :).

saludos.

Código PHP:
Ver original
  1. $startrow = 0;
  2.     // First query to find out how many reco
  3.     //     rds we have
  4.     $query = "Select * from ".$DBprefix."news ORDER BY postDate DESC";
  5.     $result = mysql_query($query);
  6.     // Number of records found
  7.     $num_record = mysql_num_rows($result);
  8.     // Number of records you want to display
  9.     //     per page
  10.    
  11.  
  12.     $display = 3;
  13.     $nav = $rqw["nave"];    
  14.    
  15.    
  16.    
  17.  
  18.  
  19. //////////////////////////////
  20.  
  21.     // Message when no records found
  22.     $XX = 'No hay resultados.';
  23.     // If there are no records then startrow
  24.     //     is 0
  25.     if (empty($startrow)) {
  26.     $startrow=0;
  27.     }
  28.     // Actual query, watch the end of the qu
  29.     //     ery, here's where we set the LIMIT per p
  30.     //     age
  31.     $query2 = "Select * from ".$DBprefix."news ORDER BY postDate DESC LIMIT $startrow, $display";
  32.     $result2 = mysql_query($query2);
  33.     //* I want only 3 results (in this case pictures) on 1 line, therefore i need a counter
  34. while($row = mysql_fetch_array($result2)){
  35.  
  36. aqui lo que se va a mostrar de las PAGINAS
  37.  
  38. }
  39.  
  40. // End loop
  41.     // Calculate the previous results, only
  42.     //     print 'Previous' if startrow is not equa
  43.     //     l to zero
  44.     if ($startrow != 0) {
  45.     $prevrow = $startrow - $display;
  46.     print("<a name='setlng' href=\"".$page_url."index.php?mod=news&amp;startrow=$prevrow\">Anterior</a> "); // Of cource here you can send more
  47.     } //variables seperated by &
  48.     // Calculate the total number of pages
  49.     $pages = intval($num_record / $display);
  50.     // $pages now contains number of pages n
  51.     //     eeded unless there are left over from di
  52.     //     vision
  53.     if ($num_record % $display) {
  54.         // has left over from division, so add one page
  55.     $pages++;
  56.     }
  57.     // Print the next pages, first check if
  58.     //     there are more pages then 1
  59.     if ($pages > 1) {
  60.     for ($i=1; $i <= $pages; $i++) { // Begin loop
  61.     $nextrow = $display * ($i - 1);
  62.     print("<a href=\"".$page_url."index.php?mod=news&amp;startrow=$nextrow\">$i</a>  "); //\\ Also here you can send more
  63.     } //variables seperatd by &
  64.     }
  65.     //End loop
  66.     // Check if we are at the last page, if
  67.     //     so, dont print 'Next'
  68.     if (!((round(($startrow / $display)+0.5)) == $pages) && $pages != 1)  {
  69.     // not the last page so print 'Next'
  70.     $nextrow = $startrow + $display;
  71.     print("<a name='setlng' href=\"".$page_url."index.php?mod=news&amp;startrow=$nextrow\">Siguiente</a>");
  72.     }
  73.     // If there are no results at all
  74.     if ($num_record < 1) {
  75.     print("<table border=0 width='90%'><tr><td>{$XX}</td></tr></table>");
  76.     }

Última edición por Curda; 28/07/2011 a las 17:35