Ver Mensaje Individual
  #1 (permalink)  
Antiguo 26/12/2010, 13:01
Ojete
 
Fecha de Ingreso: agosto-2010
Ubicación: Oakland california
Mensajes: 393
Antigüedad: 14 años, 3 meses
Puntos: 3
Por que no funciona el paginado con una consulta especifica?

si hago una consulta especifica me muestra los registros bien pero las paginas de todos los registros aunque no esten ay me explico?
trate de encontra la solucion pero pues nada de nada, espero me puede ayudar, gracias...


Código PHP:
Ver original
  1. <?php
  2.  
  3. require_once ('pagination.php');
  4.  
  5. //connect to the mysql
  6. $db = mysql_connect('localhost', 'user', 'password') or die("Could not connect database");
  7. mysql_select_db('basededatos', $db) or die("Could not select database");
  8.  
  9.  
  10.     $page = (int) (!isset($_GET["page"]) ? 1 : $_GET["page"]);
  11.     $page = ($page == 0 ? 1 : $page);
  12.     $perpage = 5;//limit in each page  
  13.     $startpoint = ($page * $perpage) - $perpage;
  14.  
  15.     $sql = mysql_query("select * FROM archivos WHERE COLORES='VERDE'  order by id desc LIMIT $startpoint,$perpage");
  16.  
  17. while($qry = mysql_fetch_array($sql)) {
  18.  
  19.  
  20. ?>

pagination.php
Código PHP:
Ver original
  1. <?php
  2.  
  3. /**
  4.  * @author Jooria Refresh Your Website <www.jooria.com>
  5.  * @copyright 2010
  6.  */
  7.  
  8. function Pages($tbl_name,$limit,$path)
  9. {
  10.     $query = "SELECT COUNT(*) as num FROM $tbl_name";        
  11.     $row = mysql_fetch_array(mysql_query($query));
  12.     $total_pages = $row['num'];
  13.  
  14.     $adjacents = "2";
  15.  
  16.     $page = (int) (!isset($_GET["page"]) ? 1 : $_GET["page"]);
  17.     $page = ($page == 0 ? 1 : $page);
  18.  
  19.     if($page)
  20.     $start = ($page - 1) * $limit;
  21.     else
  22.     $start = 0;
  23.  
  24. $sql = "SELECT id FROM $tbl_name  LIMIT $start, $limit";
  25. $result = mysql_query($sql);
  26.  
  27.     $prev = $page - 1;
  28.     $next = $page + 1;
  29.     $lastpage = ceil($total_pages/$limit);
  30.     $lpm1 = $lastpage - 1;
  31.  
  32.     $pagination = "";
  33. if($lastpage > 1)
  34. {  
  35.     $pagination .= "<div class='pagination'>";
  36. if ($page > 1)
  37.     $pagination.= "<a href='".$path."page=$prev'>&lsaquo; Previous</a>";
  38. else
  39.     $pagination.= "<span class='disabled'>&lsaquo; Previous</span>";  
  40.  
  41. if ($lastpage < 7 + ($adjacents * 2))
  42. {  
  43. for ($counter = 1; $counter <= $lastpage; $counter++)
  44. {
  45. if ($counter == $page)
  46.     $pagination.= "<span class='current'>$counter</span>";
  47. else
  48.     $pagination.= "<a href='".$path."page=$counter'>$counter</a>";                  
  49. }
  50. }
  51. elseif($lastpage > 5 + ($adjacents * 2))
  52. {
  53. if($page < 1 + ($adjacents * 2))      
  54. {
  55. for ($counter = 1; $counter < 4 + ($adjacents * 2); $counter++)
  56. {
  57. if ($counter == $page)
  58.     $pagination.= "<span class='current'>$counter</span>";
  59. else
  60.     $pagination.= "<a href='".$path."page=$counter'>$counter</a>";                  
  61. }
  62.     $pagination.= "...";
  63.     $pagination.= "<a href='".$path."page=$lpm1'>$lpm1</a>";
  64.     $pagination.= "<a href='".$path."page=$lastpage'>$lastpage</a>";      
  65. }
  66. elseif($lastpage - ($adjacents * 2) > $page && $page > ($adjacents * 2))
  67. {
  68.     $pagination.= "<a href='".$path."page=1'>1</a>";
  69.     $pagination.= "<a href='".$path."page=2'>2</a>";
  70.     $pagination.= "...";
  71. for ($counter = $page - $adjacents; $counter <= $page + $adjacents; $counter++)
  72. {
  73. if ($counter == $page)
  74.     $pagination.= "<span class='current'>$counter</span>";
  75. else
  76.     $pagination.= "<a href='".$path."page=$counter'>$counter</a>";                  
  77. }
  78.     $pagination.= "..";
  79.     $pagination.= "<a href='".$path."page=$lpm1'>$lpm1</a>";
  80.     $pagination.= "<a href='".$path."page=$lastpage'>$lastpage</a>";      
  81. }
  82. else
  83. {
  84.     $pagination.= "<a href='".$path."page=1'>1</a>";
  85.     $pagination.= "<a href='".$path."page=2'>2</a>";
  86.     $pagination.= "..";
  87. for ($counter = $lastpage - (2 + ($adjacents * 2)); $counter <= $lastpage; $counter++)
  88. {
  89. if ($counter == $page)
  90.     $pagination.= "<span class='current'>$counter</span>";
  91. else
  92.     $pagination.= "<a href='".$path."page=$counter'>$counter</a>";                  
  93. }
  94. }
  95. }
  96.  
  97. if ($page < $counter - 1)
  98.     $pagination.= "<a href='".$path."page=$next'>Next &rsaquo;</a>";
  99. else
  100.     $pagination.= "<span class='disabled'>Next &rsaquo;</span>";      
  101.     $pagination.= "</div>\n";      
  102. }                    
  103.  
  104.  
  105. return $pagination;
  106. }
  107.  
  108.  
  109. ?>