Ver Mensaje Individual
  #1 (permalink)  
Antiguo 16/05/2010, 09:15
den_22
 
Fecha de Ingreso: enero-2010
Mensajes: 198
Antigüedad: 14 años, 3 meses
Puntos: 1
Paginador problema al mostrar resultados

Hola amigos les comento tengo un codigo para hacer la paginacion de resultados, conseguí que funcionara, cuando va hacia adelante por ejemplo pagina 2 pagina 3, todo bien respeta los filtros del buscador, pero cuando va hacia atrás me vuelve a mostrar todos los usuarios de la bd.

Dejo el codigo:

Código PHP:
Ver original
  1. <?php
  2. include('header.inc');
  3.  
  4.  
  5.  
  6. $id=$_SESSION["id"];
  7. $usuario=$_SESSION["usuario"];
  8. $pag=$_GET['pag'];
  9.  
  10.  
  11.  
  12.  
  13. include_once ("connect.php");
  14.  
  15.  
  16.  
  17.  
  18. $sexo = (!empty($_POST["sexo"])
  19.     ? " sexo='".trim($_POST["sexo"])."'"
  20.         : "");
  21.  
  22. $interestin = (!empty($_POST["interestin"])
  23.         ? (!empty($sexo)
  24.                 ? " AND interestin='".trim($_POST["interestin"])."'"
  25.                 : " interestin='".trim($_POST["interestin"])."'")
  26.         : "");
  27.  
  28. $pais = (!empty($_POST["pais"])
  29.         ? (!empty($sexo) || !empty($interestin)
  30.                 ? " AND pais='".trim($_POST["pais"])."'"
  31.                 : " pais='".trim($_POST["pais"])."'")
  32.         : "");
  33.  
  34. $estadocivil= (!empty($_POST["estadocivil"])
  35.         ? (!empty($sexo) || !empty($interestin) || !empty($pais)
  36.                 ? " AND estadocivil='".trim($_POST["estadocivil"])."'"
  37.                 : " estadocivil='".trim($_POST["estadocivil"])."'")
  38.         : "");
  39.  
  40.  
  41.  
  42. $where = (!empty($sexo) || !empty($interestin) || !empty($pais) || !empty($estadocivil)  
  43.         ? " WHERE "
  44.         : "");
  45.  
  46.  
  47.  
  48. if (!isset($pag)) $pag = 1; // Por defecto, pagina 1
  49. $result = mysql_query("SELECT COUNT(*) FROM members");
  50. list($total) = mysql_fetch_row($result);
  51. $tampag = 5;
  52. $reg1 = ($pag-1) * $tampag;
  53.  
  54. function paginar($actual, $total, $por_pagina, $enlace) {
  55.   $total_paginas = ceil($total/$por_pagina);
  56.   $anterior = $actual - 1;
  57.   $posterior = $actual + 1;
  58.   if ($actual>1)
  59.     $texto = "<a href=\"$enlace$anterior\">&laquo;</a> ";
  60.   else
  61.     $texto = "<b>&laquo;</b> ";
  62.   for ($i=1; $i<$actual; $i++)
  63.     $texto .= "<a href=\"$enlace$i\">$i</a> ";
  64.   $texto .= "<b>$actual</b> ";
  65.   for ($i=$actual+1; $i<=$total_paginas; $i++)
  66.     $texto .= "<a href=\"$enlace$i\">$i</a> ";
  67.   if ($actual<$total_paginas)
  68.     $texto .= "<a href=\"$enlace$posterior\">&raquo;</a>";
  69.   else
  70.     $texto .= "<b>&raquo;</b>";
  71.   return $texto;
  72. }
  73.  
  74.  
  75. $s = "SELECT * FROM members "
  76.         . $where
  77.         . $sexo
  78.         . $interestin
  79.         . $pais
  80.         . $estadocivil
  81.         ." LIMIT $reg1, $tampag";
  82.  
  83.  
  84.  
  85.  
  86.  
  87.  
  88. $query = mysql_query($s) or die(mysql_error());
  89.  
  90.  
  91.  
  92. while($row = mysql_fetch_array($query)) {
  93.  
  94.  
  95.  
  96.  
  97.  
  98.  
  99.  
  100. ?>

Para mostrar los resultados:

Código PHP:
Ver original
  1. <?php echo paginar($pag, $total, $tampag, "mostrar_resultados.php?pag="); ?>