!--#include file="conn.asp" --> % Set rs = Server.CreateObject ("ADODB.Recordset") sql = "Select * from cnarticle order by cn_id desc" rs.Open sql,conn,1,1 %> % page=request.querystring("page") 'page值為接受值 rs.PageSize = 2 '每頁顯示記錄數(shù) rs.AbsolutePage = Page '顯示當前頁等于接收的頁數(shù) %> % For i = 1 to rs.PageSize '利用for next 循環(huán)依次讀出當前頁的記錄 if rs.EOF then Exit For end if response.write("br>文章內(nèi)容是:" rs("cn_content")) rs.MoveNext next%> % rs.close Set rs = Nothing conn.close set conn=nothing %> |
% For i = 1 to rs.PageSize if rs.EOF then Exit For end if response.write("br>文章內(nèi)容是:" rs("cn_content")) rs.MoveNext next%> |
!--#include file="conn.asp" --> % Set rs = Server.CreateObject ("ADODB.Recordset") sql = "Select * from cnarticle" rs.Open sql,conn,1,1 %> %filepath=request.servervariables("path_info")%> % page=request.querystring("page") 'page值為接受值 rs.PageSize = 2 '每頁顯示記錄數(shù) if Not IsEmpty(page) then '如果page已經(jīng)初始化... if Not IsNumeric(page) then '判斷page值是否為數(shù)字 page=1 else Page = cint(page) '接收page并化為數(shù)字型賦給page變量 end if if Page > rs.PageCount then '如果接收的頁數(shù)大于總頁數(shù) rs.AbsolutePage = rs.PageCount '設(shè)置當前顯示頁等于最后頁 elseif Page = 0 then '如果page小于等于0 rs.AbsolutePage = 1 '設(shè)置當前顯示頁等于第一頁 else rs.AbsolutePage = Page '如果大于零,顯示當前頁等于接收的頁數(shù) end if else rs.AbsolutePage=1 end if Page = rs.AbsolutePage%> % For i = 1 to rs.PageSize '利用for next 循環(huán)依次讀出當前頁的記錄 if rs.EOF then Exit For end if response.write("文章標題是:" rs("cn_title")) response.write("br>文章作者是:" rs("cn_author")) response.write("br>文章加入時間是:" rs("cn_time")) response.write("br>文章內(nèi)容是:" rs("cn_content")) response.write("hr>") rs.MoveNext Next %> form action="%=filepath%>" method="get"> !--首先保證總頁數(shù)不為1、不為0--> %if rs.pagecount>1 and rs.pagecount>0 then%> !--如果當前頁數(shù)大于1,無論何時都應(yīng)顯示首頁和上一頁的連接--> %if page>1 then%> [a Href="%=filepath%>?Page=% = 1%>">首頁/a>] [a Href="%=filepath%>?Page=% = page -1 %>">上一頁/a>] !--如果當前頁數(shù)大于1并且小于總頁面數(shù)時,顯示出尾頁和下一頁的連接--> %if pagers.pagecount then %> [a Href="%=filepath%>?Page=% = page + 1%>">下一頁/a>] [a Href="%=filepath%>?Page=% = rs.PageCount%>">尾頁/a>] !--如果當前頁數(shù)大于1并且仍大于或等于總頁面數(shù)時,不顯示出尾頁和下一頁的連接--> %else%> [下一頁] [尾頁] %end if%> !--否則,當前頁數(shù)不大于1,則只顯示尾頁和下一頁的連接--> %else%> [首頁] [上一頁] [a Href="%=filepath%>?Page=% = page + 1%>">下一頁/a>] [a Href="%=filepath%>?Page=% = rs.PageCount%>">尾頁/a>] %end if %> !--最終,總頁數(shù)若為1、為0則沒有任何連接--> %else%> [首頁] [上一頁] [下一頁] [尾頁] %end if%> [頁次:font color=red>b>%=page%>/b>/font>/%=rs.PageCount%>] [共%=rs.RecordCount%>篇 font color=red>b>%=rs.PageSize%>/b>/font>篇/頁] 轉(zhuǎn)到input name="page" size=5 value="%=page%>">頁 input type="submit" value="Enter"> /form> % rs.close Set rs = Nothing conn.close set conn=Nothing %> |
% function pagination(pagecount,pagesize,page,resultcount) Dim query, a, x, temp action = "http://" Request.ServerVariables("HTTP_HOST") Request.ServerVariables("SCRIPT_NAME") query = Split(Request.ServerVariables("QUERY_STRING"), "") For Each x In query a = Split(x, "=") If StrComp(a(0), "page", vbTextCompare) > 0 Then temp = temp a(0) "=" a(1) "" End If Next Response.Write("form method=get onsubmit=""document.location = '" action "?" temp "Page='+this.page.value;return false;"">") if page=1 then Response.Write ("[首頁] [上一頁] ") else Response.Write("[a href=" action "?" temp "Page=1>首頁/a>] ") Response.Write("[a href=" action "?" temp "Page=" (Page-1) ">上一頁/a>] ") end if if page>=pagecount then Response.Write ("[下一頁] [尾頁]") else Response.Write("[a href=" action "?" temp "Page=" (Page+1) ">下一頁/a>] ") Response.Write("[a href=" action "?" temp "Page=" pagecount ">尾頁/a>]") end if Response.Write("[頁次:font color=red>" page "/font>/" pageCount) Response.Write("] [共" resultcount "條 font color=red>" pagesize "/font>條/頁]") Response.Write(" 轉(zhuǎn)到" "input name=page size=4 value=" page ">" "頁input type=submit value=go>") End function %> |