15/01/2007, 00:40
|
| | Fecha de Ingreso: septiembre-2004 Ubicación: Lima
Mensajes: 141
Antigüedad: 19 años, 7 meses Puntos: 0 | |
Re: Buscador - PHP - MYSQL: duda Saludos , he estado leyendo tu codigo y la verdad esta muy bueno es el mejor post que hace referencia a un problema en comun , yo recien empiezo en php por eso te pediria porfavor coloques el codigo de la tabla , gracias Cita:
Iniciado por jimadri TE DEJO UN CÓDIGO QUE ESTOY USANDO Y FUNCIONA: Código PHP: <? include ("inicio.php"); // Listado de Contactos // Armo una coneccion al servidor mysql $coneccion = mysql_connect($host_db, $usuario_db, $pass_db); mysql_select_db($base_db, $coneccion); if ($tipo == "buscar") { // Busco todos los tipos de contactos disponibles $sql = "select * from categoria order by desc_cat "; $result = mysql_query($sql, $coneccion); $sql = "select * from ciudades order by desc_ciudad "; $result1 = mysql_query($sql, $coneccion); $sql = "select * from regimen order by desc_regimen "; $result2 = mysql_query($sql, $coneccion); $sql = "select * from habitacion order by desc_habitacion "; $result3 = mysql_query($sql, $coneccion); $sql = "select * from hotel order by nombre "; $result4 = mysql_query($sql, $coneccion); // Armo el formulario de busqueda ?> <form method="POST" action="lcontactos.php"> <table border="0" width="100%"> <tr bgcolor="#669966"> <td width="100%" colspan="2"><b>Buscar Hotel</b></td> </tr> <tr> <td width="30%" height="25"> <p align="right">Nombre del Hotel: </td> <td width="70%" height="25"><select size="1" name="hotel"> <option value="" selected>Todos los Hoteles</option> <? // Muestro todos los tipos de contactos para armar la lista desplegable while($myrow = mysql_fetch_array($result4)) { echo "<option value=$myrow[id_hotel]>$myrow[nombre]</option>"; } ?> </select></td> </tr> <tr> <td width="30%" height="25"> <p align="right">Ciudad: </td> <td width="70%" height="25"><select size="1" name="ciudad"> <option value="" selected>Todas las Ciudades</option> <? // Muestro todos los tipos de contactos para armar la lista desplegable while($myrow = mysql_fetch_array($result1)) { echo "<option value=$myrow[id_ciudad]>$myrow[desc_ciudad]</option>"; } ?> </select></td> </tr> <tr> <td width="30%" height="25"> <p align="right">Categoria: </td> <td width="70%" height="25"><select size="1" name="categoria"> <option value="" selected>Todas las Categorias</option> <? // Muestro todos los tipos de contactos para armar la lista desplegable while($myrow = mysql_fetch_array($result)) { echo "<option value=$myrow[id_cat]>$myrow[desc_cat]</option>"; } ?> </select></td> </tr> <tr> <td width="30%" height="25"> <p align="right">Regimen: </td> <td width="70%" height="25"><select size="1" name="regimen"> <option value="" selected>Todos los Regimenes</option> <? // Muestro todos los tipos de contactos para armar la lista desplegable while($myrow = mysql_fetch_array($result2)) { echo "<option value=$myrow[id_regimen]>$myrow[desc_regimen]</option>"; } ?> </select></td> </tr> <tr> <td width="30%" height="25"> <p align="right">Habitación: </td> <td width="70%" height="25"><select size="1" name="habitacion"> <option value="" selected>Todas las Habitaciones</option> <? // Muestro todos los tipos de contactos para armar la lista desplegable while($myrow = mysql_fetch_array($result3)) { echo "<option value=$myrow[id_habitacion]>$myrow[desc_habitacion]</option>"; } ?> </select></td> </tr> <tr> <td width="30%"></td> <td width="70%"><input type="submit" value="Buscar" name="envio"></td> </tr> </table> </form> <p align="left"> </p> <? } else { // Listamos los contactos // Armo la consulta $sql = "select * from hotel, categoria, ciudades where cod_cat = id_cat "; $sql.= "and cod_ciu = id_ciudad"; if ($hotel != '') { $sql.=" and nombre LIKE '%$hotel%'"; } if ($categoria != '') { $sql.=" and cod_cat = $categoria "; } if ($ciudad != '') { $sql.=" and cod_ciu = $ciudad "; } if ($habitacion != '') { $sql.=" and cod_habitacion = $habitacion "; } if ($regimen != '') { $sql.=" and cod_regimen = $regimen "; } $result = mysql_query($sql, $coneccion); if (mysql_error()) { echo "ERROR al buscar en la base de datos - ". mysql_errno().":". mysql_error()."<br>"; } // Calculo la cantidad de resultados $cant_resultados = mysql_num_rows($result); if ($cant_resultados >= 1) { // Muestro los resultados echo "Se han encontrado $cant_resultados resultados<br>"; ?> <? while($myrow = mysql_fetch_array($result)) { // Armo link para editar $info = "$myrow[fotogr]"; ?> <table width="100%" height="0%" border="1" cellpadding="4" cellspacing="0" bordercolor="#FFFF00"> <tr> <td height="90" rowspan="2" bgcolor="#669966"><div align="left"><? echo "<img src=$myrow[foto]>"; ?></div></td> <td width="72%" bgcolor="#669966"><p><b><? echo "Hotel $myrow[nombre]"; ?> </b>en la ciudad de<b> <? echo $myrow[desc_ciudad]; ?> </b>de categoria<b> <? echo $myrow[desc_cat]; ?></b></p> </td> <td width="12%" bgcolor="#669966"><div align="center"><a href="<? echo $info; ?>">+ info </a></div></td> </tr> <? $cadena= "$myrow[observaciones]"; ?> <tr> <td colspan="2" bgcolor="#FFFFFF"><? echo substr($cadena,0,150)?>... </td> </tr> </table> <? } // end while } else { echo "No se han encontrado resultados coincidentes<br>"; } } include("pie.php"); ?>
__________________ "Es mejor arder del todo ke consumirse poco a poco" |