数据库里有一批数据,可以按照id来进行分组,现在数据可以取出来,想把分组的数据一条条的(rs.next)通过页面展示出来.实现这样的结果:id有从0到11个分类.每个分类都对应一些数据,具体多少会不一定.第0类形成的内容以table的形式展示在页面的左端,第1类并列以表格的形式出现在右端,第2类及结果出现在页面的第二行,在第0类的下面,以此类推,会有6排表格出现.
问题:如何通过脚本实现控制表格(或者说是列)成,主要是相对应的数据也出现在相应的类下面,id也是变化的,如果数据库有这个id,则生成,没有,则不显示.
想用表格来实现,请高手帮助看一下.谢谢,郁闷这个问题好长时间了

解决方案 »

  1.   

    例如
    <%while(rs.next()){%>
    html
    <%}%>
      

  2.   

    关键的问题是while里面的语句该如何写,代码如下:
    <table width="772"  border="0" align="center" cellpadding="0" cellspacing="0" bordercolor="#CC99FF">
              <tr>
                <td bgcolor="#4E9638"><div align="left"><img src="images/title_tuijian.jpg" width="196" height="25">
                    <% try{
                         int nCurCount = 0;
     String sNowCategory = "-1";
     String sLastCategory = "-1";
                         String Query;
                         //for (int i = 0;i < 12;i++) {
     odbcQuery = "select class,aa,bb from TEST order by class desc";
     mm.Open(Query);
                        while (mm.odbcrs.next())
     {
     //out.print(edit.odbcrs.getString("class")
     //+ "&nbsp;&nbsp;"
     //+ edit.odbcrs.getString("AA") 
     //+ "&nbsp;&nbsp;"
     //+ edit.odbcrs.getString("BB")
     //+"<br>");
     try{
     sNowCategory = edit.odbcrs.getString("class");
     if (sNowCategory.compareTo(sLastCategory) != 0) //if11
     {
    nCurCount = 0;
    nCurCount++;
    System.out.println("snowcaterory:"+sNowCategory+"       "+edit.odbcrs.getString("AA"));
    System.out.println("slastcaterory:"+sLastCategory);

    if (sLastCategory.compareTo("0") != 0) //if12
    {
    sLastCategory = sNowCategory;
       //if(Integer.parseInt(sNowCategory)%2 == 0) { //if13
     %>
                </div></td>
              </tr>
              <tr>
                <td><table width="772"  border="0" align="center" cellpadding="0" cellspacing="0">
                    <tr>
                      <td width="1%" height="32" align="left" background="images/rightline.jpg"><div align="left"></div></td>
                      <td width="46%" align="left" valign="top"><div align="left"><img src="images/test/<%=Integer.parseInt(sNowCategory)%>_005.jpg" width="357" height="26"></div></td>
              <% //}else { %>
                      <td width="1%" align="left" background="images/rightline.jpg"><div align="left"></div></td>
                      <td width="51%" align="left"><img src="images/test/<%=Integer.parseInt(sNowCategory)%>_005.jpg" width="357" height="26"></td>
                      <td width="1%" background="images/rightline.jpg">&nbsp;</td>
                    </tr>
                <% 
      //} //if13结束
      } //if12结束
    %>
                    <tr>
                      <td height="23" align="left" background="images/rightline.jpg"><div align="left"></div></td>
              
            <td height="23" valign="top" background="images/new_bk3.jpg" id="td2">                    <div align="left">
              <% 
                       } //if11结束
     out.print(edit.odbcrs.getString("class")
     + "&nbsp;&nbsp;<span class=\"webname\">"
     + edit.odbcrs.getString("AA") 
     + "</span>&nbsp;&nbsp;<span class=\"webname\">"
     + edit.odbcrs.getString("BB")
     +"</span><br>");
     
     %>
    </div></td>
                      <td background="images/rightline.jpg"><div align="left"></div></td>
                      <td height="23" valign="middle" background="images/new_bk3.jpg">这个地方也是要输出数据的
              </td>
                      <td background="images/rightline.jpg">&nbsp;</td>
    </tr>
    </table>
    </td>
    <%
    }catch(Exception e) {}
     } //while结束
    %>
              </tr>
    </table>