Ver Mensaje Individual
  #3 (permalink)  
Antiguo 02/04/2009, 08:59
freakabron
 
Fecha de Ingreso: marzo-2009
Mensajes: 8
Antigüedad: 15 años, 1 mes
Puntos: 0
Información Respuesta: Problema con LIKE en consulta a la db

ESTE ES EL FORM CON EL QUE RECOJO LOS VALORES:

Cita:
<form action="hoteles.php" method="post">
<select name="categoria" size="1" class="direccion_hotel">
<option value="" default>Categorías</option>
<option value="1" >1 Estrella</option>
<option value="2" >2 Estrellas</option>
<option value="3" >3 Estrellas</option>
<option value="4" >4 Estrellas</option>
<option value="5" >5 Estrellas</option>
<option value="bed" >Bed and Breakfast</option>
<option value="gran" >Gran Turismo</option>
<option value="Hostales" >Hostales</option>
<option value="Hoteles Boutique" >Hoteles Boutique</option>
<option value=" " >Todas las Categorías</option>
</select>
<input type="submit" name="buscar" value="Buscar una categoría" class="direccion_hotel"/>

<input name="nombrehotel" type="text" id="nombre" class="direccion_hotel" size="30"/>
<input type="Submit" name="nombre" value="Buscar un hotel" class="direccion_hotel"/><!--//Submit-->

</form>

//ESTO ME IMPRIME LA CATEGORIA EN UNA PESTAÑA SI SE HA SELECCIONADO UNA CATEGORIA DE HOTEL O SI SE HA INTRODUCIDO ALGO EN EL CAMPO DE TEXTO.


Cita:
<?php
if(!empty($_POST)){
?>
<div align="left"><div style="background-image:url(images/hoteles/placa_rosa.jpg); width:127px; height:35px;" align="center">
<div class="titulo_11" style="margin-top:3px">

<?php
if($_POST['categoria']=="1") {echo "1 ESTRELLA";}
else
if($_POST['categoria']=="2") {echo "2 ESTRELLAS";}
else
if($_POST['categoria']=="3") {echo "3 ESTRELLAS";}
else
if($_POST['categoria']=="4") {echo "4 ESTRELLAS";}
else
if($_POST['categoria']=="5") {echo "5 ESTRELLAS";}
else
if($_POST['categoria']=="bed") {echo "BED & BREAKFAST";}
else
if($_POST['categoria']=="gran") {echo "GRAN TURISMO";}
else
if($_POST['categoria']=="Hostales") {echo "HOSTALES";}
else
if($_POST['categoria']=="Hoteles Boutique") {echo "HOTELES BOUTIQUE";}
else
if($_POST['categoria']==" ") {echo "TODAS LAS CATEGORIAS";}
else
if(!empty($_POST['nombrehotel'])) {echo " RESULTADOS ";}
else {
if(@mysql_fetch_array($consulta)<=0){ echo "RESULTADOS";}

}

?>
</div>
</div></div><!--/*PESTAÑA KATEGORIAS.*/-->

<?php
} //LLAVE KE CIERRA EL if(!empty($_POST))-->
?>

// DE AQUI EN ADELANTE HACE LAS CONSULTAS E IMPRIME UNA TABLA EN UN DIV PARA MOSTRAR LOS RESULTADOS


Cita:
<?php
if(!empty($_POST)){


//buskamos por categoria
if(!empty($_POST['categoria'])){

$consulta = mysql_query("SELECT * FROM `hoteles` WHERE `categoria` LIKE '%".$_POST['categoria']."%' ORDER BY `categoria`") or die(mysql_error());

}else

//buscamos por nombre
if(!empty($_POST['nombrehotel'])){

$consulta = mysql_query("SELECT * FROM `hoteles` WHERE `nombre` LIKE '%".$_POST['nombrehotel']."%' ORDER BY `categoria`") or die(mysql_error());
}
// echo "$consulta";

//si no hay resultados
if(@mysql_fetch_array($consulta)<=0){ echo "NO SE ENCONTRARON RESULTADOS, POR FAVOR REALIZA OTRA BÚSQUEDA ";}

else{

while($registro = mysql_fetch_array($consulta))
{
// print_r($registro);
$categoria = ($registro['categoria']);
$nombre = ($registro['nombre']);
$direccion = ($registro['direccion']);
$tel = ($registro['tel']);
$www = ($registro['tripledobleu']);
$email = ($registro['email']);
$municipio = ($registro['municipio']);
$foto = ($registro['foto']);


echo "

<div style='width:535px; height:120px' class='cajas_chicas'>
<div style='float:left; width:150px; height:107px' align='center'><div class='borde_fotos' style='margin-top:7px'><img src='captura_hoteles/".($foto)."' border='0' alt=".($nombre)."></div></div>
<div style='float:right; width:380px; height:107px' align='left'>
<div style='margin-top:7px' class='nombre_hotel'>".$nombre."</div>
<div class='direccion_hotel'><strong>".$categoria."</strong></div>
<div class='direccion_hotel'>".$direccion."</div>
<div class='direccion_hotel'>".$municipio.", Jalisco</div>
<div class='direccion_hotel'>".$tel."</div>
<div class='direccion_hotel' style='padding-top:7px'>

<span><a href='$registro[tripledobleu]' target='_blank'><img src='images/hoteles/[tripledobleu].gif' border='0' alt='Página Web'></a></span>

<span><img src='images/hoteles/linea.gif' border='0'></span>

<span><a href='mailto:$registro[email]'><img src='images/hoteles/email.gif' border='0' alt='E-mail'></a></span>

</div>
</div>
</div>
<br>

";
}
}//Termina el else
}//LLAVE DEL POST VACIO
?>
Es lo que creo que se necesita para detectar el problema, espero alguien pueda hecharme una manita, gracias.

Saludos.