........
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>
<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 = 0; %>
<%
} %>
</table>..........上面的代码输出为什么会出现有第一组是三行,第二组是四行呢?其实我要的是三行一组循环的。
组号
钢笔
铅笔
圆珠笔
组号圆珠笔
钢笔
铅笔
圆珠笔
组号圆珠笔
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>
<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 = 0; %>
<%
} %>
</table>..........上面的代码输出为什么会出现有第一组是三行,第二组是四行呢?其实我要的是三行一组循环的。
组号
钢笔
铅笔
圆珠笔
组号圆珠笔
钢笔
铅笔
圆珠笔
组号圆珠笔
然后你检查你的代码? 当i<3时执行if语句三次 这个正常 然后=3时执行了else语句,注意你这里面又写了一次表格阿你看看 相当于显示了 组号这一行后,又显示了一个表格 然后i才设置成0这才回到了if语句的三次,这加起来不就四次了么?
你去掉else语句里面的那个多余
<table border="1" cellspacing="0" width="161" height="20">
<tr>
<td height="20" colspan="2" align="center"><font size="2"> <%=a%> </font></td>
</tr>
的吧
其实}符号没有少,是少贴了。我上面的sql查询里的数据是这样的
字段 id a b
0 钢笔 023
0 铅笔 023
0 圆珠笔 023
0 圆珠笔 056
0 钢笔 056
0 铅笔 056
0 圆珠笔 087
0 圆珠笔 087
字段b组号
那怎么能使组号一起循环出来呢?
要象下面的效果 组号 023
钢笔
铅笔
圆珠笔
组号 056圆珠笔
钢笔
铅笔
组号 087圆珠笔
圆珠笔 如果这个回答对加70分