标题:读取数据库,并分页的方法
取消只看楼主
jt428
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2013-10-6
结帖率:100%
已结贴  问题点数:20 回复次数:0 
读取数据库,并分页的方法
分页技术源码
数据库名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">&nbsp;</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("&nbsp;");
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>");
}
%>
搜索更多相关主题的帖子: javascript include center 数据库 数据表 
2013-10-06 09:20



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-421483-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.528578 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved