peadro 0 Newbie Poster

Hello folk's I`m new to JSP and to this forum so apologies for any mistakes. I'm struggling with a drop down menu selection, I have a database with 6 locations and if I want to select any of them and I can (so far so good)but I can't get it to return to show all (which will show all locations on my table) and I need it to do this because there will be a date selection when I get this sorted.The default when the webpage is refreshed is that the table is populated with all the data from all locations and I can click the drop down menu and can select any of the other locations and the table will be populated with the data for that location. But then I want to select "All" and return the table back to default I cant get it to work, I've messed about with the code alot so I hope it still makes some sort of sense.I have to admit that I have posted this on another forum but have had only a few responses but no solution's. I'll post a jpeg of what I'm trying to create. Cheers.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">


<%@ page import="java.sql.*" %>

<html>
<img src="NRA.gif"/>
<br></br>
<HEAD>
<a href="Weather.jsp">Latest</a> | 
<a href="Daily.jsp">Daily</a> | 
<a href="Statistics.jsp">Statistics</a> | 
<a href="Login.jsp">Login</a> |
</HEAD>
<body>

<h1>Daily Weather</h1>

<%

        Connection conn = null;
        Statement stmt = null;
        ResultSet rs = null;

        try
        {
            String userName = "root";
            String password = "password";
            String url = "jdbc:mysql://localhost/weatherdb";
            
            Class.forName("com.mysql.jdbc.Driver").newInstance();
            conn = DriverManager.getConnection (url, userName, password);   
	     stmt = conn.createStatement();
	     rs = stmt.executeQuery("select location from location;");
		//String sort = request.getParameter("sortby");
		//int count = 0;

	%>

	<FORM name="form1" METHOD="POST" ACTION=""> 
	Location
	<SELECT name= "location" onchange="document.form1.submit()" >

	<OPTION name ="all" Value= "locations" >ALL</option>
	
	  <%while (rs.next()) 
            { %><OPTION name="location"> <%out.println(rs.getString("location"));%></option> 
	    <%}%>
	    
	</SELECT>
	</FORM>
	

	<FORM METHOD="POST" ACTION=""> 
	Date: 
	<SELECT name="Date" onchange="document.form1.submit()">
	<OPTION value="1">1</option><OPTION value="2">2</option><OPTION value="3">3</option><OPTION value="4">4</option><OPTION value="5">5</option><OPTION value="6">6</option>
	<OPTION value="7">7</option><OPTION value="8">8</option><OPTION value="9">9</option><OPTION value="10">10</option><OPTION value="11">11</option><OPTION value="12">12</option>
	<OPTION value="13">13</option><OPTION value="14">14</option><OPTION value="15">15</option><OPTION value="16">16</option><OPTION value="17">17</option><OPTION value="18">18</option>
	<OPTION value="19">19</option><OPTION value="20">20</option><OPTION value="21">21</option><OPTION value="22">22</option><OPTION value="23">23</option><OPTION value="24">24</option>
	<OPTION value="25">25</option><OPTION value="26">26</option><OPTION value="27">27</option><OPTION value="28">28</option><OPTION value="29">29</option><OPTION value="30">30</option>
	<OPTION value="31">31</option>
	</SELECT>

	Month
	<SELECT name="Month">
	<OPTION value="Jan">Jan</option><OPTION value="Feb">Feb</option><OPTION value="Mar">Mar</option><OPTION value="Apr">Apr</option><OPTION value="May">May</option><OPTION value="Jun">Jun</option>
	<OPTION value="Jul">Jul</option><OPTION value="Aug">Aug</option><OPTION value="Sep">Sep</option><OPTION value="Oct">Oct</option><OPTION value="Nov">Nov</option><OPTION value="Dec">Dec</option>
	</SELECT>

	Year
	<SELECT name="Year">
	<OPTION value="2011">2011</option><OPTION value="2010">2010</option><OPTION value="2009">2009</option><OPTION value="2008">2008</option><OPTION value="2007">2007</option><OPTION value="2006">2006</option>
	<OPTION value="2005">2005</option><OPTION value="2004">2004</option><OPTION value="2003">2003</option><OPTION value="2002">2002</option><OPTION value="2001">2001</option><OPTION value="2000">2000</option>
	</SELECT>

	<br>

	</FORM>



	<table border=1 >
	    <tr>
	    <th>Date</th>
	    <th>Time</th>
	    <th>Location</th>
	    <th>Precipitation</th>
	    <th> Road Temp</th>
	    <th>Air Temp</th>
	    <th>Wind speed</th>
	    </tr>
	<%
	//out.print(request.getParameter(""));
	//out.print(request.getParameter("location"));
	if(request.getParameter("location")==null||request.getParameter("location").equals("locations"))
	{
			//out.print("hello");

			rs = stmt.executeQuery("SELECT  date, time, location, precipitation, roadTemp, airTemp, windSpeed FROM weather inner join location on location.locationID=weather.locationID where date = date(now());");
	}
	if(request.getParameter("location")!=null)
	{
		//out.print("hello");
		String place = request.getParameter("location");
		
		rs = stmt.executeQuery("SELECT  date, time, location, precipitation, roadTemp, airTemp, windSpeed FROM weather inner join location on location.locationID=weather.locationID where location ='"+place+"';");

	}
            while (rs.next()) 
            { %>
		<tr>
		<td>
			<%out.println(rs.getString("date"));%>
		</td>
		<td>
			<%out.println(rs.getString("time"));%>
		</td>
		<td>
			<%out.println(rs.getString("location"));%>
		</td>
		<td>
			<%out.println(rs.getString("precipitation"));%>
		</td>
		<td>
			<%out.println(rs.getString("roadTemp"));%>
		</td>
		<td>
			<%out.println(rs.getString("airTemp"));%>
		</td>
		<td>
			<%out.println(rs.getString("windSpeed"));%>
		</td>
		</tr>
            <%}%>
	</table>
		<%
	
	
	
	}
	
	
	
        catch (Exception e)
        {
            out.println(e.getMessage()); //("Something went wrong!!!");
        }
        finally
        {
            if (rs != null) 
            {
                try 
                {
                    rs.close();
                } catch (SQLException sqlEx) { } // ignore
                rs = null;
            }
            if (stmt != null) 
            {
                try 
                {
                    stmt.close();
                } catch (SQLException sqlEx) { } // ignore
                stmt = null;
            }
        }

%>
<hr/>

<p> &copy; 2011 Paul O'Donnell</p>
</body>
</html>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.