1

This is a search function that pulls information depending on search criteria and prints it in a table. Also I have a few different pages for different restaurants that I want to open depending on what dish i click on. Basically, when I click on the href I want it to recognize which specific restaurant it is and take me there.

This is my code:

<%
        String value=request.getParameter("search");
        Class.forName("com.mysql.jdbc.Driver").newInstance();
        Connection conn = DriverManager.getConnection("**************", "******", "*******");
        Statement st=conn.createStatement();
        ResultSet rs = st.executeQuery("SELECT menu.name, menu.info, menu.price, restaurants.name from menu,"
                + " restaurants where restaurants_restaurantID=RestaurantID AND (menu.name like '%"
                + value
                + "%' "
                + "or menu.info like '%"
                + value
                + "%' or menu.category like '%"
                + value
                + "%' "
                + "or menu.kitchen like '%"
                + value
                + "%' or quick_choose like '%" + value + "%')");
    %>
        <table>
        <tr class="head">
          <td>Name:</td>
          <td>Info:</td>
          <td>Price:</td>
          <td>Restaurant:</td>
          <td>Location:</td>
         
        </tr>    
      <%
      
       while (rs.next()){ 
      %>
        <tr class="content">
          <td class="name"><%=rs.getString("name")%></td>
          <td class="info"><%=rs.getString("info")%></td>
          <td class="price"><%=rs.getInt("price")%></td>
          <td class="restaurant"><%=rs.getString("restaurants.name")%></td>
          <td class="location"><a href="#" %>>Show</a>
          
        </tr>
      <%
       }
      %>
      </table>

    <%conn.close();%>

    </div>
4

1 回答 1

0

您可以使用以下内容。在这里您可以点击餐厅名称进入相应页面

  <%
  while (rs.next()){ 
  %>
    <tr class="content">
      <td class="name"><%=rs.getString("name")%></td>
      <td class="info"><%=rs.getString("info")%></td>
      <td class="price"><%=rs.getInt("price")%></td>
      <td class="restaurant"><%=rs.getString("restaurants.name")%></td>
      <td class="location"><a href="ShowRestaurant.jsp?restoid=<%=rs.getString("name")%>">Show</a>

    </tr>
  <%
   }
  %>

现在在ShowRestaurant.jsp页面中使用以下代码获取餐厅名称

request.getParameter("restoid")

然后从数据库中获取数据并像在主页上一样显示

在这里我假设

  1. 您的"name"餐厅是独一无二的。
  2. ShowRestaurant.jsp?restoid=resto1将显示详细信息 resto1
于 2013-01-07T18:00:43.033 回答