Link to home
Start Free TrialLog in
Avatar of Gar04
Gar04

asked on

Need Help with formatting JSP

Hello Experts,
i have a jsp page below that has a for loop for reading in data
i am having difficulty getting the results to output in repeated rows
i think that i am placing the end of the for loop in the wrong place
to allow the rows to repeat when there is multiple data.
it works but it just looks bad
can anyone help me sort this out
it should be an easy 300 pts for yeah
unlike many of my other threads!!
Gaz :)

<%@ page contentType="text/html; charset=iso-8859-1" language="java" import="java.sql.*" %>
<% Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection conn = null;
CallableStatement cs = null;
try
{
  conn = DriverManager.getConnection("jdbc:odbc:BillBoardCompany");
  cs = conn.prepareCall("{Call SiteSearchQ(?, ?, ?)}");
 
  String snames[] = request.getParameterValues("SiteName");
    for( int ii=0; snames!=null && ii<snames.length; ii++ )
    {
      String siteName = snames[ii];
  //String siteName = request.getParameter("SiteName");
  //if( siteName == null ) siteName = "";
  int selCyc=Integer.parseInt( request.getParameter("SelectCyc"));
  int year=Integer.parseInt( request.getParameter("SelectYear"));
 
      //cs.setString(1, siteName );
      cs.setString(1,siteName);
    cs.setInt(2, selCyc );
    cs.setInt(3, year);
   
  ResultSet rs = cs.executeQuery();
  %>
      
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>SearchRes</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">



</head>
<body>
<form name=Bookform Action="BookingPage.jsp" method="post">
  <table width="95%" border="1" align="center" cellpadding="0" cellspacing="1" bgcolor="#FFFFFF">
    <!--DWLayoutTable-->
    <tr>
      <td height="74" colspan="4" align="left" valign="bottom" bgcolor="#FFFFFF">
        <div align="right"></div>
        <div align="left"></div>
        <div align="left"></div>
        <table width="99%" height="34" border="1" align="center" cellpadding="0" cellspacing="0" bordercolor="#006699">
          <tr bordercolor="#0033CC">
            <td width="245" height="20" align="center" valign="middle"> <div align="center"></div>
              <strong><font color="#000000" size="1">&nbsp;</font></strong><font color="#000000" size="1"><strong>Site
              Location</strong></font></td>
            <td width="155" height="20" align="center" valign="middle"> <div align="center"><font color="#000000" size="1"><strong>Site
                Format</strong></font></div></td>
            <td width="83" align="center" valign="middle"> <font color="#000000" size="1">&nbsp;<strong>Prismatic</strong></font></td>
            <td width="72" align="center" valign="middle" bgcolor="#FFFFFF"> <div align="center"><font color="#000000" size="1"><strong>Illuminated</strong></font></div></td>
            <td width="67" align="center" valign="middle"> <div align="center"><font color="#000000" size="1"><strong>CycleStart</strong></font></div></td>
            <td width="119" align="center" valign="middle"> <div align="center"><font color="#000000" size="1"></font></div>
              <div align="center"></div>
              <div align="center"><font color="#000000" size="1"><strong>CycleEnd</strong></font></div></td>
            <td colspan="2" align="center" valign="middle"> <div align="center">
                <div align="center"><font color="#000000" size="1"></font></div>
                <div align="center"><font size="1"><strong>Book</strong></font></div>
                <font color="#000000" size="1"></font></div>
              <div align="center"></div></td>
          </tr>
          <% while (rs.next())
        { %>
          <tr bgcolor='#EEEFF3' onMouseOver="this.bgColor='#B2C4F0';" onMouseOut="this.bgColor='#EEEFF3';">
            <input name="siteId" type="hidden" value="<%=rs.getString("SiteID")%>">
            <td height="12"> <div align="center"></div>
              <div align="center"></div>
              <div align="center"><font color="#000000" size="1"><%=rs.getString("SiteLocation")%></font></div></td>
            <td><div align="center"><font color="#000000" size="1"><%=rs.getString("SiteType")%></font></div></td>
            <td><div align="center"><font color="#000000" size="1"><%=rs.getString ("Prismatic")%></font></div></td>
            <td><div align="center"><font color="#000000" size="1"><%=rs.getString ("Illuminated")%></font></div></td>
            <input name="cycleId" type="hidden" value="<%=rs.getString("CycleID")%>">
            <td><div align="center"><font color="#000000" size="1"><%=rs.getString ("CycleStart")%></font></div></td>
            <td><div align="center"><font color="#000000" size="1"><%=rs.getString ("CycleEnd")%></font></div></td>
            <input name="bookYear" type="hidden" value="<%=rs.getString("BookYear")%>">
            <td width="120"><div align="center"><font color="#000000" size="1">
                <input type="checkbox" name="bookingsNo" value="<%=rs.getString("BookingsNo")%>">
                </font></div></td>
          </tr>
          <%} // end the while loop %>
              <%}// end the for loop %>
        </table>
        <div align="center"> </div></td>
    </tr>
    <tr valign="middle">
      <td colspan="4" align="center" bgcolor="#FFFFFF"></td>
    </tr>
    <tr valign="middle">
      <td height="21" colspan="4" align="center" bgcolor="#FFFFFF"><!--DWLayoutEmptyCell-->&nbsp;</td>
    </tr>
    <tr valign="middle">
      <td align="center" bgcolor="#FFFFFF"><font size="1">Company Name</font></td>
      <td align="center" bgcolor="#FFFFFF"><div align="left">
          <input type="text" name="compName" value="">
        </div></td>
      <td align="center" bgcolor="#FFFFFF"><font size="1">Company Address</font></td>
      <td align="center" bgcolor="#FFFFFF"><div align="left">
          <input type="text" name="compAddress" value="">
        </div></td>
    </tr>
    <tr valign="middle">
      <td align="center" bgcolor="#FFFFFF"><font size="1">City </font></td>
      <td align="center" bgcolor="#FFFFFF"><div align="left">
          <input type="text" name="cityName" value="">
        </div></td>
      <td align="center" bgcolor="#FFFFFF"><font size="1">Country</font></td>
      <td align="center" bgcolor="#FFFFFF"><div align="left">
          <input type="text" name="countryName" value="">
        </div></td>
    </tr>
    <tr valign="middle">
      <td align="center" bgcolor="#FFFFFF"><font size="1">Postcode</font></td>
      <td align="center" bgcolor="#FFFFFF"><div align="left">
          <input type="text" name="postCode" value="">
        </div></td>
      <td align="center" bgcolor="#FFFFFF"><font size="1">Phone Number</font></td>
      <td align="center" bgcolor="#FFFFFF"><div align="left">
          <input type="text" name="phoneNum" value="">
        </div></td>
    </tr>
    <tr valign="middle">
      <td align="center" bgcolor="#FFFFFF"><font size="1">Fax Number</font></td>
      <td align="center" bgcolor="#FFFFFF"><div align="left">
          <input type="text" name="faxNum" value="">
        </div></td>
      <td align="center" bgcolor="#FFFFFF"><font size="1">Email Address</font></td>
      <td align="center" bgcolor="#FFFFFF"><div align="left">
          <input type="text" name="emailAdd" value="">
        </div></td>
    </tr>
    <tr valign="middle">
      <td align="center" bgcolor="#FFFFFF"><font size="1">Product Name</font></td>
      <td align="center" bgcolor="#FFFFFF"><div align="left">
          <input type="text" name="prodName" value="">
        </div></td>
      <td align="center" bgcolor="#FFFFFF"><font size="1">Product Category</font></td>
      <td align="center" bgcolor="#FFFFFF"><div align="left">
          <input type="text" name="prodCat" value="">
        </div></td>
    </tr>
    <tr valign="middle">
      <td align="center" bgcolor="#FFFFFF"><font size="1">Price</font></td>
      <td align="center" bgcolor="#FFFFFF"><div align="left">
          <input type="text" name="priceNum" value="">
        </div></td>
      <td align="center" bgcolor="#FFFFFF"><!--DWLayoutEmptyCell-->&nbsp;</td>
      <td align="center" bgcolor="#FFFFFF"><!--DWLayoutEmptyCell-->&nbsp;</td>
    </tr>
    <tr valign="middle">
      <td colspan="4" align="center" bgcolor="#FFFFFF"><input type=submit name=Submit value="BookIt"></td>
    </tr>
  </table>
</form>
<%
}
    catch (Exception e)
    {
      e.printStackTrace() ;
     out.print("Exception: " + e);
        

    }
    finally
    {
     if( cs != null ) try { cs.close(); } catch( Throwable t ) { t.printStackTrace(); }
     if( conn != null ) try { conn.close(); } catch( Throwable t ) { t.printStackTrace(); }
    }
%>
</body>
</html>
Avatar of sompol_kiatkamolchai
sompol_kiatkamolchai
Flag of Thailand image

Is there any error or exception throw out?
I think you just remove this line, I cannot see the matching for loop.

<%}// end the for loop %>
ASKER CERTIFIED SOLUTION
Avatar of TimYates
TimYates
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
or, if you want a form (and table) for each loop round the for loop, then move the end for down to after the table :-)

Tim
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Gar04
Gar04

ASKER

tim, you are the bomb!!!
cheers mate
it works fine
i was in a muddle with the formatting
my system is coming together now and it has been greatly helped
by some of the code you provided cos i have analysed and modified it for other
parts too.

sompol, thanks for you input too!!

:)
Gaz
:-)  Good luck with it fella :-)

Glad I could help!

Hope you are ok!

Tim