asp access 大数据量的分页的方法
asp教程 access 大数据量的分页的方法
'本款分页效果支持'分页,分页效果:首页 上一页 ... 2 3 4 5 6 7 ... 下一页 最后一页这种分页模式,有论坛风格
'id title content status updatetime
'1 t1 c1 1 2010-5-26 21:16:06
'2 t2 c2 1 2010-5-26 21:16:09
'3 t3 c3 1 2010-5-26 21:16:12
'4 t4 c4 1 2010-5-26 21:16:15
'5 t5 c5 1 2010-5-26 21:16:23
DB="database/db1.mdb"
path=Server.MapPath(DB)
set conn=server.createobject("adodb.Connection")
connstr="provider=Microsoft.Jet.OLEDB.4.0;Data Source="&path
conn.Open connstr
Set rs=server.CreateObject("adodb.recordset")
%>
<!-- #include file="conn.asp" -->
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
<style>
td{
font-size:12px;
}
</style>
</HEAD><BODY>
<TABLE border=1 cellspacing=0 cellpadding=0 width=500>
<TR>
<td align="center">ID</td>
<TD height="22" align="center">标题</TD>
<TD align="center">时间</TD>
</TR>
<%
'十万条以上数据的分页的方法
'作者:wangsdong
'来源:zzzyk.com
'原创文件,转载请保留此信息,谢谢
keyword=request("keyword")
page=request("page")
If page="" Or Not IsNumeric(page) then page=1 Else page=CInt(page)
page_size=2
q1=" and status>0"
If keyword<>"请输入关键词" and keyword<>"" then
q1=q1&" and title like '%"&keyword&"%'"
end If
if page>1 then
sql="select top "&page_size&" id,title,content,updatetime from news where 1=1 and id<(select min(id) from (select top "&(page-1)*page_size&" id from news where status>0"&q1&" order by id desc) as c1)"
else
sql="select top "&page_size&" id,title,content,updatetime from news where 1=1"
end if
sql=sql&q1&" order by id desc"
set rs=server.CreateObject("adodb.recordset")
rs.open sql,conn,1,1
if not rs.eof then
do while not rs.eof
id=rs("id")
title=rs("title")
content=rs("content")
updatetime=rs("updatetime")
'*************循环的内容开始************************
%>
<TR>
<td><%=id%></td>
<TD height="22"><%=title%></TD>
<TD><%=updatetime%></TD>
</TR>
<%
'*************循环的内容结束************************
rs.movenext
loop
end if
rs.close
%>
<tr><td colspan="3" height="30" align="center">
<%
'分页开始
'计算总页数
page_count=1
sql="select count(*) as t from news where 1=1"&q1
rs.open sql,conn,1,1
if rs.eof then
else
recordset_count=rs("t")
if recordset_count mod page_size=0 then
page_count=recordset_countpage_size
else
page_count=recordset_countpage_size+1
end if
end if
rs.close
'分页,分页效果:首页 上一页 ... 2 3 4 5 6 7 ... 下一页 最后一页
if page=1 then
response.write "首页 上一页 "
else
response.write "<a href=""?page=1&keyword="&keyword&""">首页</a> <a href=""?page="&page-1&"&keyword="&keyword&""">上一页</a> "
end if
if page>4 then
s=page-3
response.write "..."
else
s=1
end if
if page<=page_count-3 then
e=page+3
else
e=page_count
end if
for i=s to e
if i=page then
response.write "<font color=""#FF8000""><b>"&i&"</b></font> "
else
response.write "<a href=""?page="&i&"&keyword="&keyword&""">"&i&"</a> "
end if
nextif page<page_count-3 then
response.write "..."
end if
if page=CInt(page_count) then
response.write "<span>下一页 最后一页</span>"
else
response.write "<span><a href=""?page="&page+1&"&keyword="&keyword&""">下一页</a> <a href=""?page="&page_count&"&keyword="&keyword&""">最后一页</a></span>"
end if%>
</td></tr>
</TABLE>
</BODY>
</HTML>
补充:asp教程,技巧与性能优化