读取数据库,并分页的方法
分页技术源码数据库名12.mdb
数据表名:sp1
文件一 fenye.asp
<%@ language="javascript" %>
<!--#include file="paging.asp"-->
<html>
<head>
<title>分页显示表记录</title>
<style type="text/css">
<!--
.style1 {font-size: 14px}
.style2 {font-family: "黑体";font-size: 16px;color: #8B1A1A;}
-->
</style>
</head>
<body >
<h2 align="center"> </h2>
<h2 align="center" class="style2">已经添加的内容</h2>
<span class="style1"><p>
<% star=Server.CreateObject("ADODB.Connection");
star.open("Driver={Microsoft Access Driver (*.mdb)};DBQ=" + Server.MapPath("12.mdb"));
zd=Server.CreateObject("ADODB.Recordset");
sql="select * from sp1 order by ID desc";
zd.Open (sql,star,3);
zd.pagesize=6; //分6行显示
if (0==Request("page").Count) {Page=1;}
else {Page=parseInt(Request("Page"))}
if (Page<1) {Page=1;}
if (Page>zd.PageCount) {Page=zd.PageCount;}
ShowOnePage(zd,Page);
Response.Write(" ");
Response.Write("<div align=center>");
if (!(1==Page))
{
Response.Write("<A HREF=fenye.asp?Page=1>首页</A>");
Response.Write("≡");
Response.Write("<A HREF=fenye.asp?Page="+(Page-1)+">上一页</A>");
Response.Write("≡");
}
if (!(zd.PageCount==Page))
{Response.Write("<A HREF=fenye.asp?Page="+(Page+1)+">下一页</A>");
Response.Write("≡");
Response.Write("<A HREF=fenye.asp?Page="+zd.PageCount+">末页</A>");
Response.Write("≡");}%>
</p>
</span>
<p class="style1">页数:
<font color="blue">
<%=Page%>/<%=zd.PageCount%></font></p>
</body>
</html>
文件二
<%
function ShowOnePage( zd, page )
{Response.Write("<center><table border=1>");
Response.Write("<tr><td>序号</td><td>ID</td><td>标题</td><td>文件地址</td></tr>");
zd.AbsolutePage = page;
var ipage;
for (ipage=1; ipage<=zd.pagesize; ipage++)
{
if (!zd.EOF)
{
Response.Write("<tr align=middle>");
RecNo = (page - 1) * zd.pagesize + ipage;
Response.Write("<td>" + RecNo + "</td>");
for(i=0; i<zd.Fields.Count; i++)
{
Response.Write("<td>" + zd.Fields(i).Value + "</td>");
}
Response.Write("</tr>");
zd.MoveNext();
}
}
Response.Write("</table></center>");
}
%>