欢迎光临
我们一直在努力

分页函数

建站超值云服务器,限时71元/月

函数如下:

<%

private function fenye(rs, pagesize,args)

dim intcur

dim intpagesize

dim total

dim inttotal

args = split(args,",")

if request.querystring("page")="" then

intcur=1

page = "first"

else

select case request("page")

case "first"

intcur=1

case "previous"

intcur=cint(request("curpage"))

intcur=intcur-1

case "next"

intcur=cint(request("curpage"))

intcur=intcur+1

case "last"

intcur=cint(request("lastpage"))

case else

intcur=request("page")

end select

end if

%>

<table width="100%" border="0" cellpadding="0" cellspacing="0">

<tr>

<td colspan="2" height="58">

<%

if rs.eof then

response.write "没有栏目:("

else

intpagesize=pagesize

rs.pagesize=intpagesize

if not rs.eof then

rs.absolutepage=intcur

end if

total=rs.recordcount

inttotal=rs.pagecount

dim i

i = 0

%>

<table border = 1 align = center>

<tr>

<%

dim n

n = 0

do while n <= ubound(args)%>

<th>

<%response.write args(n)%>

</th>

<%

n = n + 1

loop

%>

</tr>

<%

do while not rs.eof and i<intpagesize%>

<tr>

<%

dim l

l = 0

do while l <= ubound(args)

%>

<td>

<%=rs(args(l))%>

</td>

<%

l = l + 1

loop

%>

</tr>

<%

i = i + 1

rs.movenext

loop

%>

</table>

<%

end if%>

</td>

</tr>

</table>

<div align="center"><br>

<%=intcur%> /<%=inttotal%>

<% if intcur>1 then %>

<a href="index.asp?page=previous&curpage=<%=intcur%>">上一页</a>

<%else%>

上一页

<%end if

intcur=cint(intcur)

inttotal=cint(inttotal)%>

<%if intcur<inttotal then%>

<a href="index.asp?page=next&curpage=<%=intcur%>">下一页</a>

<%else%>

下一页

<%end if%>

</div>

<%

rs.close

set rs = nothing

end function

%>

测试页面如下:

<!–#include file = "fenye.inc"–>

<%

dim conn

dim connstr

dim rst

on error resume next

connstr="dbq="+server.mappath("nwind.mdb")+";defaultdir=;driver={microsoft access driver (*.mdb)};"

set conn=server.createobject("adodb.connection")

conn.open connstr

set rst = server.createobject("adodb.recordset")

rst.open "select * from orders",conn,1,1

call fenye(rst,7,"orderid,customerid,shipvia")

rst.close

set rst = nothing

conn.close

set conn = nothing

%>

说明:

使用时在asp页面顶部加入

<!–#include file = "fenye.inc">

在需要分页的地方调用函数:

如:call fenye(rst,7,"orderid,customerid,shipvia")

函数原型:

variant fenye(recordset rs,integer pagesize,string args)

参数说明如下:

rs: 传入的recordset

n: 要求每页显示的记录数

columns: 要求显示的数据库中的字段

做这样一个分页函数是因为有时自己写分页的时候觉得不是那么方便,每个地方都写一遍很浪费,也看到很多朋友都在问这个问题,所以写这样一个函数大家参考一下吧,第一次写这种东西,感觉很低级,但是还是希望大家捧场。。。。。谢谢!!!欢迎各种意见和建议!顺便说一下,这种ado的分页方法,我觉得实在是效率很低,因为我每次只要7条记录但是却要取出一个上百条甚至上千条的纪录集,如果一个服务器端的数据量少也就罢了,如果。。。。唉。。。所以,以后会再做几个不同原理的分页函数!

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » 分页函数
分享到: 更多 (0)

相关推荐

  • 暂无文章