ASP分页程序代码之一
'数据库路径,应用本分页程序所在文件已有的不用加
<%
'---------------------------------------------------------
'本
程序适合access数据库asp程序分页,其它类型数据库可参考。
'本例程序适合给 xxx.asp 或 xxx.asp?page=1 类型的网址进行分页。
'效果:javascript:if(this.width>740)this.width=740" border=undefined>
'有明确注释,直接套用,需修改的部位不多。
'------------------------------------------------------------
%>
<%'=============分页定义开始,可放在数据库打开前或后
dim action
action=request.QueryString("action")
Const MaxPerPage=10 '定义每页显示记录数,可根据实际自定义
dim totalPut
dim CurrentPage
dim TotalPages
dim j
dim
sql if Not isempty(request("page")) then
currentPage=Cint(request("page"))
else
currentPage=1
end if
'=============分页定义结束%>
<%'=============打开数据库数据表,要以这种方式打开
set rs=server.CreateObject("adodb.recordset")
rs.open "select * from news where link=1 and shgg<>1 order by fincount desc",conn,1,1
%>
<%'=============分页类代码开始,需放在数据库数据表打开后
if err.number<>0 then
response.write "
数据库中暂时无数据
"
end if
if rs.eof And rs.bof then
Response.Write "
对不起,没有符合条件记录!
"
else
totalPut=rs.recordcount
if currentpage<1 then
currentpage=1
end if
if (currentpage-1)*MaxPerPage>totalput then
if (totalPut mod MaxPerPage)=0 then
currentpage= totalPut \ MaxPerPage
else
currentpage= totalPut \ MaxPerPage + 1
end if
end if
if currentPage=1 then
showContent
showpage totalput,MaxPerPage,""&;request.ServerVariables("script_name")&;""
else
if (currentPage-1)*MaxPerPage
rs.move (currentPage-1)*MaxPerPage
dim bookmark
bookmark=rs.bookmark
showContent
showpage totalput,MaxPerPage,""&;request.ServerVariables("script_name")&;""
else
currentPage=1
showContent
showpage totalput,MaxPerPage,""&;request.ServerVariables("script_name")&;""
end if
end if
end if
'=============分页类代码结束%>
<%'=============循环体开始
sub showContent
dim i
i=0
do while not rs.eof%>
<%
i=i+1
if i>=MaxPerPage then Exit Do
rs.movenext
loop
rs.close '释放资源
set rs=nothing
End Sub
'=============循环体结束%>
<%'=============放置分页显示开始
Function showpage(totalnumber,maxperpage,filename)
Dim n
If totalnumber Mod maxperpage=0 Then
n= totalnumber \ maxperpage
Else
n= totalnumber \ maxperpage+1
End If %>
<%
End Function
'=============放置分页显示结束%>