Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <%@page contentType="text/html" pageEncoding="UTF-8"%>
- <%@page import="java.sql.*"%>
- <!DOCTYPE html>
- <html>
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
- <title>Search Cars</title>
- <link href="" type="text/css" rel="stylesheet">
- <style>
- table, th, td {
- border: 1px solid black;
- }
- </style>
- </head>
- <body>
- <h1>Search Cars</h1>
- <form action= "" method="POST">
- <center>
- Car Make:
- <select name="cartype" id="cartype" onchange="this.form.submit();">
- <option value=0>Select Car Make</option>
- <%
- String cartype= null;
- int b=0;
- try{
- String Query="Select * FROM auction_items GROUP BY cartype";
- Class.forName("com.mysql.jdbc.Driver").newInstance();
- Connection conn = DriverManager.getConnection("jdbc:mysql://localhost/auction","root","cenk");
- Statement st= conn.createStatement();
- ResultSet rs= st.executeQuery(Query);
- while(rs.next()){
- %><option value ="<%=rs.getInt("ProductID")%>"
- <%
- if(request.getParameter("cartype") !=null){
- if(rs.getInt("ProductID")==Integer.parseInt(request.getParameter("cartype")))
- {
- out.print("Selected");
- cartype=rs.getString("cartype");
- b=1;
- }
- }
- %>><%=rs.getString("cartype")%></option><%
- }
- }catch(Exception e){
- e.printStackTrace();
- }
- %>
- </select>
- </p>
- Car model:
- <select name="carmodel" id="carmodel" onchange="this.form.submit();">
- <option value="0">Select Car Model</option>
- <%
- String query = null;
- String carmod = null;
- try{
- query="Select * FROM auction_items WHERE cartype=? Group by carmodel";
- Class.forName("com.mysql.jdbc.Driver").newInstance();
- Connection con= DriverManager.getConnection("jdbc:mysql://localhost/auction","root","cenk");
- PreparedStatement psmt=con.prepareStatement(query);
- psmt.setString(1,cartype);
- ResultSet rs = psmt.executeQuery();
- while(rs.next()){
- %><option value ="<%=rs.getInt("ProductID")%>" <%
- if(request.getParameter("carmodel") !=null){
- if(rs.getInt("ProductID")==Integer.parseInt(request.getParameter("carmodel")))
- {
- out.print("Selected");
- carmod= rs.getString("carmodel");
- b=2;
- }
- }
- %>><%=rs.getString("carmodel")%></option><%
- }
- }catch(Exception e){
- e.printStackTrace();
- }%>
- </select>
- </p>
- <table class="table table-bordered table-striped" style="width: 90%">
- <tr>
- <th>Car</th>
- <th>Image</th>
- <th>Car Make</th>
- <th>Car Model</th>
- <th>Car Description</th>
- <th>Start Date</th>
- <th>End Date</th>
- </tr>
- <%
- try{
- Class.forName("com.mysql.jdbc.Driver").newInstance();
- Connection con= DriverManager.getConnection("jdbc:mysql://localhost/auction","root","cenk");
- String Query3 = null;
- if(b==1)
- Query3 = "SELECT ProductID,images,cartype,carmodel,cardetails,startDate,enddate FROM auction_items WHERE cartype=?";
- if(b==2)
- Query3 = "SELECT ProductID,images,cartype,carmodel,cardetails,startDate,enddate FROM auction_items WHERE carmodel=?";
- PreparedStatement psmt=con.prepareStatement(Query3);
- if(b==1)
- psmt.setString(1,cartype);
- if(b==2)
- psmt.setString(1,carmod);
- ResultSet rs = psmt.executeQuery();
- while(rs.next()){
- %>
- <tr>
- <td><input type="radio" name="pid" value ="<%=rs.getInt("ProductID")%>"</input></td>
- <td><a href="bidding.jsp"><%=rs.getString("images")%></a></td>
- <td><a href="bidding.jsp"><%=rs.getString("cartype")%></a></td>
- <td><a href="bidding.jsp"><%=rs.getString("carmodel")%></a></td>
- <td><a href="bidding.jsp"><%=rs.getString("cardetails")%></a></td>
- <td><a href="bidding.jsp"><%=rs.getString("startDate")%></a></td>
- <td><a href="bidding.jsp"><%=rs.getString("enddate")%></a></td>
- </tr>
- <%
- }
- }
- catch(Exception e){
- e.printStackTrace();
- }
- %>
- </table>
- </center>
- </form>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement