<%'=============分頁定義開始,可放在數據庫打開前或後
dim action
action=request.QueryString("action")
Const MaxPerPage=20 '定義每頁顯示記錄數,可根據實際自定義
dim totalPut
dim CurrentPage
dim TotalPages
if Not isempty(request("page")) then
currentPage=Cint(request("page"))
else
currentPage=1
end if
'=============分頁定義結束%>
<% '=============打開數據庫數據表,要以這種方式打開
set rs=server.CreateObject("adodb.recordset")
sql="select * from p_log order by id desc"
rs.open sql,conn,1,1
'sql="select * from ht_cp where"
%>
<%'=============分頁類代碼開始,需放在數據庫數據表打開後
if err.number<>0 then
response.write "<p align='center'>數據庫中暫時無數據</p>"
end if
if rs.eof And rs.bof then
Response.Write "<p align='center'>對不起,沒有符合條件記錄!</p>"
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<totalPut then
rs.move (currentPage-1)*MaxPerPage
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
<!--------------------------------------------分頁位置---------->
<%showpage totalput,MaxPerPage,""&request.ServerVariables("script_name")&"" %><!------------------------------------------------------>
<%'=============放置分頁顯示開始
Function showpage(totalnumber,maxperpage,filename)
Dim n
If totalnumber Mod maxperpage=0 Then
n= totalnumber \ maxperpage
Else
n= totalnumber \ maxperpage+1
End If %>
<form method=Post action=<%=filename%>>
<p align="center">
<%If CurrentPage<2 Then %>
首 頁 上一頁
<% Else %>
<a href=<% = filename %>?page=1>首 頁</a>
<a href=<% = filename %>?page=<% = CurrentPage-1 %>>上一頁</a>
<% End If
If n-currentpage<1 Then %>
下一頁 尾 頁
<% Else %>
<a href=<% = filename %>?page=<% = (CurrentPage+1) %>>下一頁</a>
<a href=<% = filename %>?page=<% = n %>>尾 頁</a>
<% End If %>
頁次:<b><font color=red><% = CurrentPage %></font></b>/<b><% = n %></b>頁 <b><%=maxperpage%></b>個記錄/頁 共<b><%=totalnumber %></b>個記錄
轉到:<select name="cndok" onChange="Javascript:location=this.options[this.selectedIndex].value;">
<%
for i = 1 to n
if i = CurrentPage then%>
<option value="<% = filename %>?page=<%=i%>" selected>第<%=i%>頁</option>
<%else%>
<option value="<% = filename %>?page=<%=i%>">第<%=i%>頁</option>
<%
end if
next
%>
</select></font>
</form>
<%End Function
'=============放置分頁顯示結束%>