主题:怎么把数据循环在指定的位置?
........
String sql = "";
String a = "";
int i=0;
sql="select a from ab where id='0' ";
rs = stmt.executeQuery( sql );
while(rs.next())
{ if(i != 3){
a=rs.getString("a").trim();
%>
<table border="1" cellspacing="0" width="161" height="20">
<tr>
<td height="20" colspan="2" align="center"><font size="2"> <%=a%> </font></td>
</tr>
<% i++; %>
<%} else { %></table><br/><br/>
<p align="left"><b><font size="2"> </font><font size="4">组号</font></b></p>
<tr>
<td height="20" colspan="2" align="center"><font size="2"> <%=a%> </font></td>
</tr>
<% i = 1; %>
<%}
} %>
</table>
..........
我的数据库的数据是:
字段 id a b
0 钢笔 023
0 铅笔 023
0 圆珠笔 023
0 圆珠笔 056
0 钢笔 056
0 铅笔 056
0 圆珠笔 087
0 圆珠笔 087
字段a是货物名称,b是组号
以上代码已经实现功能如下:
组号
钢笔
铅笔
圆珠笔
组号
圆珠笔
钢笔
铅笔
组号
圆珠笔
圆珠笔
但现在我要使数据库里的组号一起循环出来怎么做呢???
要象下面的效果:
组号 023
钢笔
铅笔
圆珠笔
组号 056
圆珠笔
钢笔
铅笔
组号 087
圆珠笔
圆珠笔
String sql = "";
String a = "";
int i=0;
sql="select a from ab where id='0' ";
rs = stmt.executeQuery( sql );
while(rs.next())
{ if(i != 3){
a=rs.getString("a").trim();
%>
<table border="1" cellspacing="0" width="161" height="20">
<tr>
<td height="20" colspan="2" align="center"><font size="2"> <%=a%> </font></td>
</tr>
<% i++; %>
<%} else { %></table><br/><br/>
<p align="left"><b><font size="2"> </font><font size="4">组号</font></b></p>
<tr>
<td height="20" colspan="2" align="center"><font size="2"> <%=a%> </font></td>
</tr>
<% i = 1; %>
<%}
} %>
</table>
..........
我的数据库的数据是:
字段 id a b
0 钢笔 023
0 铅笔 023
0 圆珠笔 023
0 圆珠笔 056
0 钢笔 056
0 铅笔 056
0 圆珠笔 087
0 圆珠笔 087
字段a是货物名称,b是组号
以上代码已经实现功能如下:
组号
钢笔
铅笔
圆珠笔
组号
圆珠笔
钢笔
铅笔
组号
圆珠笔
圆珠笔
但现在我要使数据库里的组号一起循环出来怎么做呢???
要象下面的效果:
组号 023
钢笔
铅笔
圆珠笔
组号 056
圆珠笔
钢笔
铅笔
组号 087
圆珠笔
圆珠笔