Foros del Web » Programando para Internet » PHP »

Buscador PHP (Consultas con Match)

Estas en el tema de Buscador PHP (Consultas con Match) en el foro de PHP en Foros del Web. Por un lado tenemos el formulario : @import url("http://static.forosdelweb.com/clientscript/vbulletin_css/geshi.css"); Código HTML: Ver original < meta http-equiv = "Content-Type" content = "text/html; charset=UTF-8" >   < ...
  #1 (permalink)  
Antiguo 29/10/2012, 13:34
 
Fecha de Ingreso: noviembre-2007
Ubicación: Irun
Mensajes: 79
Antigüedad: 16 años, 6 meses
Puntos: 0
Buscador PHP (Consultas con Match)

Por un lado tenemos el formulario :

Código HTML:
Ver original
  1. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  2.  
  3. <form name="frmBuscar" action="buscar.php" method="POST">
  4.     <label> Introduce el texto a buscar</label>
  5.     <input type="text" name="txtTexto" value="" />
  6.     <label>Busqueda avanzada :</label>
  7.     <label>Categoria : </label><select name="txtCategoria"  id="txtCategoria">
  8. <option value=""></option>
  9.       <option value="Vehiculos">Vehiculos</option>
  10.       <option value="Inmobiliaria">Inmobiliaria</option>
  11.       <option value="Electronica">Electronica</option>
  12.       <option value="CasaJardin">Casa y jardin</option>
  13.       <option value="ModaBebes">Moda y bebés</option>
  14.       <option value="Ocio">Ocio</option>
  15.       <option value="Negocios">Negocios</option>
  16.       <option value="Empleo">Empleo</option>
  17.       <option value="Contactos">Contactos</option>
  18.       <option value="Diversos">Diversos</option>
  19.  </select>
  20.     <input type="submit" value="Enviar" name="BtnEnviar" />
  21. </form>

Y en "buscar.php"

Hace las consultas de de si se busca en categoria + txtTexto y sus diferentes combinaciones :

Código PHP:
Ver original
  1. <?php
  2. include("../funciones/conexion.php");
  3. $busqueda=$_POST['txtTexto'];
  4. $categoria=$_POST['txtCategoria'];
  5. $tipo=$HTTP_GET_VARS['tipo'];
  6. $id=$HTTP_GET_VARS['id'];
  7. $ubicacion=$HTTP_GET_VARS['ubicacion'];
  8. if ((!empty($busqueda)) && (!empty($categoria)))
  9. {
  10.  $sqlBuscar ="MATCH (id,dniCliente,categoria,regimen,tipo,titulo,ubicacion,descripcion,precio,img)
  11.                              AGAINST ('$busqueda' IN BOOLEAN MODE)
  12.                              FROM anuncio
  13.                              WHERE MATCH (id,dniCliente,categoria,regimen,tipo,titulo,ubicacion,descripcion,precio,img)
  14.                              AGAINST ('$busqueda' IN BOOLEAN MODE) AND  id IN (SELECT id FROM anuncio WHERE categoria LIKE '$categoria')";  
  15. $_SESSION['consulta']= $sqlBuscar;
  16. }
  17.  
  18. header("Location: index.php");

Cuando busca solo en categoria la session funciona bien, y se reenvia a index de forma correcta... sin embargo cuando entra en juego el campo $busqueda ... aparece el error


Código PHP:
Ver original
  1. include("../funciones/conexion.php");
  2. $limit = 6;
  3. if (!isset($_SESSION['orden']))
  4. {
  5.     $_SESSION['orden']='ORDER BY precio ASC';
  6. }
  7. if ( !isset ( $_SESSION['consulta']) )
  8.     {
  9.         error_reporting(E_ERROR);
  10.     }
  11.  else
  12.     {
  13. $consulta=$_SESSION['consulta'];
  14. $orden=$_SESSION['orden'];
  15. $pag = (int) $_GET["pag"];
  16. function operacion ()
  17. {
  18.     $pag=$pag--;
  19.     return $pag;
  20.     echo  "<a href=\"?pag=$pag\">Anterior</a>";
  21. }
  22.  
  23. if ($pag < 1)
  24. {
  25.    $pag = 1;
  26. }
  27. echo $consulta."<br>";
  28. $offset = ($pag-1) * $limit;
  29. $sql = "(SELECT SQL_CALC_FOUND_ROWS * $consulta $orden LIMIT $offset, $limit,$conexion"or die("error");
  30. echo $sql."<br>";
  31. $sqlTotal = "SELECT FOUND_ROWS() as total";
  32. $rs = mysql_query($sql);
  33. $rsTotal = mysql_query($sqlTotal);
  34. $rowTotal = mysql_fetch_assoc($rsTotal);
  35. $total = $rowTotal["total"];
  36. while ($row = mysql_fetch_assoc($rs))
  37.       {
  38.             $imagen=$row['img'];
  39.             $tipo=$row['tipo'];      
  40.             $id=$row['id'];
  41.             $ubicacion=$row['ubicacion'];
  42.            echo "<tr><td> <b>Titulo</b> :".$row['titulo']."<td>";
  43.            echo "<td><b> Categoria</b>:".$row['categoria']."<td>";
  44.            echo "<td><b> Tipo</b> :<a href='buscar.php?tipo=$tipo'>".$row['tipo']."</a><td>";
  45.            if (!empty($row['regimen']))
  46.            {
  47.                echo "<td><b> Regimen</b> :".$row['regimen']."<td>";
  48.            }
  49.            echo "<td><b> Ubicacion</b> :<a href='buscar.php?ubicacion=$ubicacion'>".$row['ubicacion']."<td>";
  50.            echo "<td><b> Precio</b> :".$row['precio']."€<td>";
  51.            echo "<td><a href='buscar.php?id=$id'><img src=../intranet/FotosAnunciosPequenos/$imagen alt='Foto'></a></td></tr>";
  52.       }
  53.          
  54.         $totalPag = ceil($total/$limit);
  55. if(($pag - 1) > 0) {
  56. echo "<a href='index.php?pag=".($pag-1)."'>Anterior</a> ";
  57. }
  58. for ($i=1; $i<=$totalPag; $i++){
  59. if ($pag == $i) {
  60. echo $pag;
  61. } else {
  62. echo "<a href='index.php?pag=$i'>$i</a> ";
  63. } }
  64. if(($pag + 1)<=$totalPag) {
  65. echo " <a href='index.php?pag=".($pag+1)."'>Siguiente </a>";
  66. }
  67.          
  68.     }

El sistema además tiene un paginado para gestionar la aparición de los resultados. Ya os digo que cuando trabaja solo con txtCategoria funciona bien... ¿En donde está el error?

Etiquetas: formulario, html, mysql, sql, buscadores
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 14:50.