'=====================================================================================
'ASP百度风格分页
'作者:上善若水
'变量解释:
'pUrl 需要分页的网页url
'pPage 页码
'pSize 每页显示数目
'pCount 总页数
'pMax 分页栏显示的页码数目
'pNum1 限制显示页码数目的参数1
'pNum2 限制显示页码数目的参数2
'pNum3 限制显示页码数目的参数3
'pAbsolute 记录集的absolutepage属性
'使用方法: 在需要分页的页面头部加入如下代码:
' dim p,Current
' rs.pagesize = 10
' if Current>rs.pagecount then Current=rs.pagecount
' if request.QueryString("p")<>"" then
' Current=request.querystring("p")
' else
' Current=1
' end if
' rs.absolutepage=Current
' count=0
' 然后在显示分页的位置用该语句调用:
' call showPage("2.asp",request.QueryString("p"),rs.pagesize,rs.pagecount,"10",rs.absolutepage,"9","20","19")
'注: 该例完全仿照百度搜索的分页编写,分页情况根据记录集的数目而定。
'=====================================================================================
Sub showPage(pUrl,pPage,pSize,pCount,pMax,pAbsolute,pNum1,pNum2,pNum3)
Dim max,begin,truepage,truenum,p
'----------------------------------------------------------------------------------
max = pMax
begin = 1
If pPage <> "" Then
truepage = pPage '当前页码
max = truepage+pNum1
End If
'------------------------若总数大于或等于总页数则总数等于总页数----------------------
If max >= pCount Then
max = pCount
End If
'-------------------------保证显示的页码数目为自定意的范围内--------------------------
If max >= pNum2 Then
begin = max - pNum3
End If
'--------------------------当不是第一页时显示上一页链接----------------------------
If pPage <> "" And pPage <> 1 Then
Response.Write("<a class='zhaoyingjiefenye' href="""&pUrl&"&p="&Cint(pPage) - 1&"""><</a> ")
End If
'----------------------------生成页码,只有一页时不显示分页页码---------------------------
for truenum = begin to max
If truenum = 1 And pPage = "" And pCount > 1 Then
Response.Write("<span class='zhaoyingjiefenye_1'>"&truenum&"</span> ")
ElseIf truenum = Cint(pPage) And pCount > 1 Then
Response.Write("<span class='zhaoyingjiefenye_1'>"&truenum&"</span> ")
ElseIf rs.pagecount > 1 Then
Response.Write("<a class='zhaoyingjiefenye' href="""&pUrl&"&p="&truenum&""">"&truenum&"</a> ")
End If
next
'-----------------------------------当不是最后一页时显示下一页链接------------------------------------
If pPage <> "" And pAbsolute <> pCount And pAbsolute >= 0 Then
Response.Write("<a class='zhaoyingjiefenye' href="""&pUrl&"&p="&Cint(pPage) + 1&""">></a>") '不为空时传值为当前页加1
End If
If pPage = "" And pCount > 1 Then
Response.Write("<a href="""&pUrl&"&p=2"">></a>") '为空时是第一页所以直接传2
End If
'------------------------------------------------------------------------------------------------------
End Sub
'Codes From '============
sql=sql & " Order By id Desc"
rs.open sql,conn,1,1
if not rs.eof then
dim p,Current
rs.pagesize = 5
if Current>rs.pagecount then Current=rs.pagecount
if request.QueryString("p")<>"" then
Current=request.querystring("p")
else
Current=1
end if
rs.absolutepage=Current
count=0
for i= 1 to rs.pagesize
if rs.eof then
exit for
end if
' 然后在显示分页的位置用该语句调用:
' call showPage("2.asp",request.QueryString("p"),rs.pagesize,rs.pagecount,"10",rs.absolutepage,"9","20","19")
'*****************************************************************************
%>
--------------------这里是循环展示的记录---------------------------------
<%
rs.movenext
next
else
response.Write("nothing...")
end if
%>
<%'这里是分页的地方
call showPage("?aid="&aid&"&bclassid="&bclassid&"&dt="&dt&"&lx="&lx&"&shi="&shi&"&jg1="&jg1&"&jg2="&jg2&"&jgid="&jgid&"&dtzmid="&dtzmid&"&keyword="&keyword&"",request.QueryString("p"),rs.pagesize,rs.pagecount,"5",rs.absolutepage,"10","10","10")
%>