int i = 0;
while(result1.next())
{
if($i%3 == 0)
out.println("</tr><tr>");
$i++在中间加上这几句就可以了,
不过还要考虑到不够的时候你应该要补齐,
以及刚刚好的时候不需要再加多一个</tr><tr>,
这些就要你自己写啦,我只能帮你写一个简单的....
while(result1.next())
{
if($i%3 == 0)
out.println("</tr><tr>");
$i++在中间加上这几句就可以了,
不过还要考虑到不够的时候你应该要补齐,
以及刚刚好的时候不需要再加多一个</tr><tr>,
这些就要你自己写啦,我只能帮你写一个简单的....
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<LINK href="picture/Style.css" rel=stylesheet />
<head>
<title>Print information</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<!--media=print 这个属性可以在打印时有效-->
<style media=print>
.Noprint{display:none;}
.PageNext{page-break-after: always;}
</style><style>
.tdp
{
border-bottom: 1 solid #000000;
border-left: 1 solid #000000;
border-right: 0 solid #ffffff;
border-top: 0 solid #ffffff;
}
.tabp
{
border-color: #000000 #000000 #000000 #000000;
border-style: solid;
border-top-width: 2px;
border-right-width: 2px;
border-bottom-width: 1px;
border-left-width: 1px;
}
.NOPRINT {
font-family: "宋体";
font-size: 9pt;
}</style></head><body >
<center class="Noprint" >
<p align="left">
<input name="button" type=button onclick=document.all.WebBrowser.ExecWB(7,1) value=打印预览 />
<OBJECT id=WebBrowser classid=CLSID:8856F961-340A-11D0-A96B-00C04FD705A2 height=0 width=0>
</OBJECT>
<input type=button value=页面设置 onclick=document.all.WebBrowser.ExecWB(8,1)>
</p>
<p> <br/>
</p>
</center><table width="100%" border="0">
<tr>
<%! String post_num;%>
<%! String user_num;%>
<%! String address_num;%>
<%! String id_num;%>
<%! String where_code;%>
<%! int i;%>
<%
try
{
request.setCharacterEncoding("gb2312");
where_code=(String)request.getParameter("print_txt");
where_code=where_code.trim();
//str2="jdbc:odbc:"+str1
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver").newInstance();
Connection connect;
connect=DriverManager.getConnection("jdbc:odbc:shanghaitoday","shtodaydb","s1n0db");
Statement state1;
state1=connect.createStatement();
String strQuery1="select * from customer_table "+where_code+"";
ResultSet result1=state1.executeQuery(strQuery1);
System.out.println(where_code);
System.out.println(strQuery1);
while(result1.next())
{
id_num=result1.getString("name_id");
id_num=id_num.trim();
user_num=result1.getString("name");
user_num=user_num.trim();
address_num=result1.getString("address");
address_num=address_num.trim();
post_num=result1.getString("post");
post_num=post_num.trim();
i++;
if(i%4==0)
{
System.out.println(i);
%><tr><%
}
%><td>
<table width="30%" border="1" cellpadding="0" cellspacing="0" bordercolorlight="#FFFFFF" bordercolordark="#000000">
<tr>
<td>
<table width="300" height="100" border="0">
<tr >
<td height="25">
<div align="left"> <%=post_num%></div></td>
</tr>
<tr>
<td height="25"><div align="center"></div>
<div align="center"><%=user_num%> (收)</div></td>
</tr>
<tr>
<td height="25" valign="top"><div align="center"><%=address_num%></div></td>
</tr>
<tr>
<td valign="top"><div align="right">编号:<%=id_num%> </div></td>
</tr>
</table>
</td>
</tr>
</table>
</td>
<%
if(i%4==0)
{
System.out.println(i);
%></tr><%
}
}
connect.close();
}
catch(Exception e)
{
System.err.println("done exception"+e);
}
finally
{
System.out.println(post_num);
System.out.println(user_num);
System.out.println(address_num);
System.out.println(id_num);
}
%>
</tr>
</table></body>
</html>
比如在数据库里的记录有6条,要求每行显示3个,我上面的代码在运行后,第一行是3个,但是到第二行就显示一个了,还有2个到第三行去了,这是怎么回事啊??????