日期:2014-05-17  浏览次数:20715 次

读取数据库的留言板信息,分页显示出错
这个是我查看留言板的代码

<body>
<p align="center">所有访客留言</p> 
<table width="732" height="*" border="1" align="center" cellpadding="1" cellspacing="0" bordercolordark="#ffffff" bordercolor="#ffffff" bordercolorlight="#0066ff">
  <tr bgcolor="#CCCCFF">
  <td height="22" colspan="5" align="center"><a href="index.jsp?choice=5.jsp">增加留言</a></td>
  </tr>
  <%
Connection con = DriverManager.getConnection("jdbc:odbc:banji");
Statement sql = con.createStatement();
ResultSet rs = sql.executeQuery("select * from message ORDER BY m_date DESC");
String color="";
String strpages=(String)request.getParameter("pages");
int pages=0;
if(strpages==null){
pages=0;
}else{
  pages=Integer.parseInt(strpages);
}
rs.last();
int sqan=4,i=0,fcount=0;
int count=rs.getRow();
int countpage=count/sqan;

if(count%sqan>0) countpage=countpage+1;
if(pages<0) pages=0;
if(pages>countpage-1) pages=countpage-1;
fcount=pages*sqan+1;
int fpage=(count-fcount)/sqan+1;
out.print(fpage);
rs.absolute(fcount);
rs.previous();

while(rs.next()){
  int id=rs.getInt("id");
  String username=rs.getString("m_name");
  String time=rs.getString("m_date");
  String title=rs.getString("m_title");
  String email=rs.getString("m_email");
  String content=rs.getString("m_info");
  if(content==null) content="";
  if(color==""){
  color="#ffffff";
}else{
  color="";
}
%>
  <tr bgcolor="<%=color%>">
  <td align="center" width="86" height="22"><div align="left">留言人:</div></td>
  <td align="center" width="158"><%=username%>&nbsp;</td>
  <td height="22" colspan="2" align="left">留言主题:</td>
  <td width="298" height="22" align="center"><%=title%>&nbsp;</td>
  </tr>
  <tr bgcolor="<%=color%>">
  <td width="86" height="22" align="center"><div align="left">日期:</div></td>
  <td width="158" height="22" align="center"><%=time%></td>
  <td height="22" colspan="3" rowspan="3" align="left" valign="top"><%=content%>&nbsp;</td>
  </tr>
  <tr bgcolor="<%=color%>">
  <td height="22" align="center"><div align="left">Email:</div></td>
  <td height="22" align="center"><%=email%>&nbsp;</td>
  </tr>
  <tr bgcolor="<%=color%>">

  <%
i++;if(i==sqan) break;
  }
try{
con.close();
}catch(Exception e){
}
%>
  </tr>
  <tr align="right" bgcolor="#CCCCFF">
&nb