回 帖 发 新 帖 刷新版面

主题:怎么把数据循环在指定的位置?

........
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

圆珠笔 
圆珠笔

回复列表 (共3个回复)

沙发

首先,查询语句要查询两个字段:select a,b from ab where id='0' 
其次,循环显示就可以了:
a=rs.getString("a").trim();
b=rs.getString("b").trim();

<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"> <%=b%> </font></td>
<td height="20" colspan="2" align="center"><font size="2"> <%=a%> </font></td>
</tr>

板凳

不知你看懂我写的题目吗!我要的是这样输出的效果:

组号 023
钢笔
铅笔 
圆珠笔 


组号 056

圆珠笔 
钢笔
铅笔 


组号 087

圆珠笔 
圆珠笔

就象你说的用这样select a,b from ab where id='0' 语句怎么能实现我需要的效果呢?如果象你所说的话就会是是以下的效果:

组号 

钢笔     023
铅笔     023
圆珠笔   023 


组号 

圆珠笔   056
钢笔     056
铅笔     056


组号 

圆珠笔   087
圆珠笔   087

这样和我要求的完全两样了。

3 楼

那就把b字段和组号放在一行就行了,排版格式问题罢了

我来回复

您尚未登录,请登录后再回复。点此登录或注册