用“limit”实现分页!
用“limit”实现分页!我认为这种方法比较好!!

<%@page contentType="text/html;charset=GB2312"%>
<%@include file=
"inc.jsp"%>
<Script language=
"JavaScript">
//打开新窗口函数NewsWindow
function NewsWindow(id)
{
window.open('newswind.jsp?id='+id,'infoWin', 'height=400,width=600,scrollbars=yes,resizable=yes');
}
</Script>
<%@include file=
"head.htm"%>
<body bgcolor=
"#999999">
<%
int i;
int fpage=10;
//分页单位
int allpage;
//总页数
int pages;
//接受的页码变量
inttpage=1;
//当前页
int spage;
//开始页
int intRowCount;
//总记录数
sql=
"select * from new_sz " ;
rs = apple.select(sql);
rs.last();
intRowCount=rs.getRow();
allpage=(intRowCount+fpage-1) / fpage;
if (request.getParameter(
"pages")==null) {
pages=1;
} else {
pages = new Integer(request.getParameter(
"pages")).intValue();
}
if(pages > allpage ){
// pages == 0){
cpage = 1;
} else {
cpage = pages;
}
spage=(cpage-1)*fpage;
apple. closeConn();

sql=
"select * from new_sz order by id desc limit "+ spage +","+fpage ;
rs = apple.select(sql);

%>
<table border=1 align='center' width='71%'>
<tr>
<td width=
"47%">
<div align=
"center">主题</div>
</td>
<td width=
"21%">
<div align=
"center">作者</div>
</td>
<td width=
"32%">
<div align=
"center">时间</div>
</td>
</tr>
<% while (rs.next()) { %>
<td width=
"47%"><a href="javascript:NewsWindow(<%=rs.getInt("ID")%>)"><u>
<%String title=rs.getString(
"title");
title=new String(title.getBytes(
"ISO-8859-1"),"GB2312" );
%>
<%=title%></u></a></td>
<td width=
"21%" align="center">
<%String author=rs.getString(
"author");
author=new String(author.getBytes(
"ISO-8859-1"),"GB2312" );
%>
<%=author%>
<div align=
"center"></div>
</td>
<td width=
"32%" align="center"><%=rs.getString("Date")%>
<%
out.println(
"</td></tr>");

}

apple.closeConn();

%><TD width='50%'>

<center><font color=
"green" > 所有页数:
<%out.println(allpage);%>
&nbsp;&nbsp;当前页数:
<%out.println(cpage);%> &nbsp;&nbsp; &nbsp;&nbsp; <%if(cpage>1){%><a href=
"show.jsp?pages=<%=tpage-1 %>">前一页</a><%}%> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<%if(cpage<allpage){%><a href="show.jsp?pages=<%=tpage+1 %>">后一页</a><%}%> </form>
&nbsp;&nbsp;</font></center>
</div></TD>



lunzi   2004-11-17 16:40:00 评论:0   阅读:2504   引用:0
兼容性问题 @2004-11-17 19:35:58  hofman
如果是Mysql,当然用limit实现分页比较方便,但是很多数据库比如oracle,postgres等都不支持limit,这个办法自然就失效了。

发表评论>>

署名发表(评论可管理,不必输入下面的姓名)

姓名:

主题:

内容: 最少15个,最长1000个字符

验证码: (如不清楚,请刷新)

Copyright@2004-2010 powered by YuLog