Ver Mensaje Individual
  #6 (permalink)  
Antiguo 13/01/2012, 13:40
Avatar de pampa_
pampa_
 
Fecha de Ingreso: mayo-2006
Mensajes: 334
Antigüedad: 18 años
Puntos: 1
Respuesta: pasar consulta mysql por GET

Código PHP:
Ver original
  1. <!--COMIENZO PAGINADOR-->
  2.     <?php
  3.     $link = mysql_connect("com", "anuncios", "234");
  4.     mysql_select_db("anuncios", $link);
  5.      
  6.                     $filtro='';
  7.                     $tipo=$_POST['interes'];
  8.                     $provincia=$_POST['sprovincia'];
  9.                     $year=$_POST['ano'];
  10.                     $categoria=$_POST['scategoria'];
  11.                     $marca=$_POST['smarca'];
  12.                     $min=$_POST['pminimo'];
  13.                     $max=$_POST['pmaximo'];
  14.                     $busqueda=$_POST['bpalabra'];
  15.      
  16.      
  17.                     if(($provincia!="selec") AND ($year!="") AND ($categoria!="selec") AND ($marca!="selec") AND ($min!="selec") AND ($max!="selec") AND ($tipo!="todo") AND ($tipo!="se vende") AND ($busqueda!="bpalabra")){
  18.                         $filtro="provincia=\"$provincia\" AND year=\"$year\" AND tipo1=\"$categoria\" AND marca=\"$marca\" AND precio>=\"$min\" AND precio<=\"$max\" AND tipo2=\"$tipo\" AND texto=\"$busqueda\"";
  19.                     }elseif(($provincia!="selec") AND ($year!="") AND ($categoria!="selec") AND ($marca!="selec") AND ($min!="selec") AND ($max!="selec") AND ($tipo!="todo") AND ($tipo!="se compra") AND ($busqueda!="bpalabra")){
  20.                         $filtro="provincia=\"$provincia\" AND year=\"$year\" AND tipo1=\"$categoria\" AND marca=\"$marca\" AND precio>=\"$min\" AND precio<=\"$max\" AND tipo2=\"$tipo\" AND texto=\"$busqueda\"";
  21.                     }elseif(($provincia!="selec") AND ($year!="") AND ($categoria!="selec") AND ($marca!="-seleccione marca") AND ($min!="selec") AND ($max!="selec") AND ($tipo!='se vende') AND ($tipo!='se compra') AND ($busqueda!="bpalabra")){
  22.                         $filtro="provincia=\"$provincia\" AND year=\"$year\" AND tipo1=\"$categoria\" AND marca=\"$marca\" AND precio>=\"$min\" AND precio<=\"$max\" AND tipo2='se vende' AND tipo2='se compra' AND texto=\"$busqueda\"";
  23.                     }elseif(($provincia!="-selec") AND ($year!="") AND ($categoria!="selec") AND ($marca!="-seleccione marca") AND ($min!="selec") AND ($max!="selec") AND ($tipo!="todo") AND ($tipo!="se compra")){
  24.                         $filtro="provincia=\"$provincia\" AND year=\"$year\" AND tipo1=\"$categoria\" AND marca=\"$marca\" AND precio>=\"$min\" AND precio<=\"$max\" AND tipo2=\"$tipo\"";
  25.                     }elseif(($provincia!="selec") AND ($year!="") AND ($categoria!="selec") AND ($marca!="selec") AND ($min!="selec") AND ($max!="selec")){
  26.                         $filtro="provincia=\"$provincia\" AND year=\"$year\" AND tipo1=\"$categoria\" AND marca=\"$marca\" AND precio>=\"$min\" AND precio<=\"$max\"";
  27.                     }elseif(($provincia!="selec") AND ($year!="") AND ($categoria!="selec") AND ($min!="selec") AND ($max!="selec")){
  28.                         $filtro="provincia=\"$provincia\" AND year=\"$year\" AND tipo1=\"$categoria\" AND precio>=\"$min\" AND precio<=\"$max\"";
  29.                     }elseif(($provincia!="selec") AND ($categoria!="selec") AND ($min!="selec") AND ($max!="selec")){
  30.                         $filtro="provincia=\"$provincia\" AND tipo1=\"$categoria\" AND precio>=\"$min\" AND precio<=\"$max\"";
  31.                     }elseif(($provincia!="selec") AND ($min!="selec") AND ($max!="selec")){
  32.                         $filtro="provincia=\"$provincia\" AND precio>=\"$min\" AND precio<=\"$max\"";
  33.                     }elseif(($min!="selec") AND ($max!="selec")){
  34.                         $filtro="precio>=\"$min\" AND precio<=\"$max\"";
  35.                     }elseif(($min!="selec") AND ($max=="selec")){
  36.                         $filtro="precio>=\"$min\"";
  37.                     }elseif(($min=="selec") AND ($max!="selec")){
  38.                         $filtro="precio<=\"$max\"";
  39.                     }elseif(($provincia!="selec")){
  40.                         $filtro="provincia=\"$provincia\"";
  41.                     }elseif(($categoria!="selec")){
  42.                         $filtro="tipo1=\"$categoria\"";
  43.                     }elseif(($year!="")){
  44.                         $filtro="year=\"$year\"";
  45.                     }elseif(($busqueda!="")){
  46.                         $filtro="texto like '%$busqueda%'";
  47.                     }elseif(($marca!="selec")){
  48.                         $filtro="marca=\"$marca\"";
  49.                     }elseif(($tipo!="todo")){
  50.                         $filtro="tipo2=\"$tipo\"";
  51.                     }elseif(($tipo=="todo")){
  52.                         $filtro="tipo2='se vende' or tipo2='se compra'";
  53.                     }elseif(($min=="selec") AND ($max=="selec")){
  54.                         $filtro="id_anunciante=90000";
  55.                     }elseif(($busqueda=="")){
  56.                         $filtro=$_GET['bpalabra'];
  57.                     }
  58.  
  59.      $RegistrosAMostrar=4;
  60.    
  61.      //estos valores los recibo por GET
  62.      if(isset($_GET['pag'])){
  63.       $RegistrosAEmpezar=($_GET['pag']-1)*$RegistrosAMostrar;
  64.       $PagAct=$_GET['pag'];
  65.       //caso contrario los iniciamos
  66.      }else{
  67.       $RegistrosAEmpezar=0;
  68.       $PagAct=1;
  69.      }
  70.      
  71.     $Resultado = mysql_query("SELECT * FROM anuncios WHERE $filtro ORDER BY id_anuncio LIMIT $RegistrosAEmpezar, $RegistrosAMostrar", $link);
  72.     $NroRegistros=mysql_num_rows(mysql_query("SELECT * FROM anuncios WHERE $filtro", $link));              
  73.                     // CODIGO PARA BUSCAR SI HAY UN ERROR EN LA CONSULTA
  74.                     $error = mysql_error($link);  // $link es la variable de conexión
  75.                        
  76.                     if ($error!=null)
  77.                     {
  78.                         print("Ocurrio; el Siguiente Error:\n ".$error);
  79.                         exit;
  80.                     }
  81.                     // FIN DE LA BUSQUEDA DE ERROR
  82.      
  83.      
  84.      echo "<table border='1px'>";
  85.      while($MostrarFila=mysql_fetch_array($Resultado)){
  86.       echo "<tr>";
  87.       echo "<td>".$MostrarFila['titulo']."</td>";
  88.       echo "<td><img src='".$MostrarFila['foto1']."' WIDTH=105 HEIGHT=97></img></td>";
  89.       echo "<td>".$MostrarFila['precio']."</td>";
  90.       echo "</tr>";
  91.      }
  92.      echo "</table>";
  93.    
  94.      //******--------determinar las páginas---------******//
  95.      
  96.      $PagAnt=$PagAct-1;
  97.      $PagSig=$PagAct+1;
  98.      $PagUlt=$NroRegistros/$RegistrosAMostrar;
  99.    
  100.      //verificamos residuo para ver si llevará decimales
  101.      $Res=$NroRegistros%$RegistrosAMostrar;
  102.      // si hay residuo usamos funcion floor para que me
  103.      // devuelva la parte entera, SIN REDONDEAR, y le sumamos
  104.      // una unidad para obtener la ultima pagina
  105.      if($Res>0) $PagUlt=floor($PagUlt)+1;
  106.      
  107.      //desplazamiento
  108.      echo $filtro;
  109.      echo "<a onclick=\"Pagina('1')\">Primero</a> ";
  110.      if($PagAct>1) echo "<a onclick=\"Pagina('$PagAnt')\">Anterior</a> ";
  111.      echo "<strong>Pagina ".$PagAct."/".$PagUlt."</strong>";
  112.      if($PagAct<$PagUlt)  echo " <a onclick=\"Pagina('$PagSig')\">Siguiente</a> ";
  113.      echo "<a onclick=\"Pagina('$PagUlt')\">Ultimo</a>";
  114.     ?>
  115.     <!--FIN PAGINADOR-->


Estas son mis paginas, pero es que no me sale lo que quiero