<%@ page import="java.sql.*" %> <%@ page import="servlet.conexion_mysql" %> <%@ page contentType="text/html; charset=UTF-8" %> <% request.setCharacterEncoding("UTF-8"); %> <% String filtroRestaurante = request.getParameter("restaurante"); String filtroTipoComida = request.getParameter("tipo_comida"); %> Restaurantes - Guía Gastronómica

Guía Gastronómica

Descubre los mejores restaurantes y sus deliciosos platillos

Filtrar Restaurantes
Limpiar
<% try (Connection con = conexion_mysql.getConnection()) { StringBuilder sql = new StringBuilder("SELECT * FROM restaurantes WHERE 1=1"); if (filtroRestaurante != null && !filtroRestaurante.isEmpty()) { sql.append(" AND id_restaurantes = ?"); } sql.append(" ORDER BY nombre_restaurante"); try (PreparedStatement psRest = con.prepareStatement(sql.toString())) { if (filtroRestaurante != null && !filtroRestaurante.isEmpty()) { psRest.setInt(1, Integer.parseInt(filtroRestaurante)); } try (ResultSet rsRest = psRest.executeQuery()) { boolean encontrado = false; while (rsRest.next()) { int idRest = rsRest.getInt("id_restaurantes"); String nombre = rsRest.getString("nombre_restaurante"); String direccion = rsRest.getString("direccion"); String telefono = rsRest.getString("telefono"); String email = rsRest.getString("email"); // Verificar filtro de tipo de comida boolean mostrar = true; if (filtroTipoComida != null && !filtroTipoComida.isEmpty()) { String tipoCheckSql = "SELECT COUNT(*) FROM platos_restaurante WHERE id_restaurante = ? AND tipo_comida = ?"; try (PreparedStatement psTipo = con.prepareStatement(tipoCheckSql)) { psTipo.setInt(1, idRest); psTipo.setString(2, filtroTipoComida); try (ResultSet rsTipo = psTipo.executeQuery()) { rsTipo.next(); mostrar = rsTipo.getInt(1) > 0; } } } if (!mostrar) continue; encontrado = true; %>

<%= nombre %>

<%= direccion != null ? direccion : "Dirección no disponible" %>
<% if (telefono != null && !telefono.trim().isEmpty()) { %>
<%= telefono %>
<% } %> <% if (email != null && !email.trim().isEmpty()) { %>
<%= email %>
<% } %>
Servicios
<% String sqlServicios = "SELECT s.nombre_servicio FROM restaurante_servicio rs " + "JOIN servicios s ON rs.id_servicio = s.id_servicio " + "WHERE rs.id_restaurante = ? ORDER BY s.nombre_servicio"; try (PreparedStatement psServ = con.prepareStatement(sqlServicios)) { psServ.setInt(1, idRest); try (ResultSet rsServ = psServ.executeQuery()) { boolean hayServicios = false; while (rsServ.next()) { hayServicios = true; out.println("" + rsServ.getString("nombre_servicio") + ""); } if (!hayServicios) { out.println("Sin servicios especificados"); } } } %>
Menú
<% } // fin while if (!encontrado) { %>

No se encontraron restaurantes

Intenta ajustar los filtros de búsqueda

<% } } } } catch (Exception e) { %>
Error al cargar los datos: <%= e.getMessage() %>
<% } %>