' 檔案pageft.asp '---------------------------------------------------------------------------------- <% ' 作者:阿言 ' 功能:ASP利用Mysql分頁,利用偶然PHP分頁所改 ' 取得目前頁碼及筆數起始點函數 Function getPageNum(perpage) if(request("page")="" or request("page")<=1) then page = 1 startline = 0 else page = request("page") startline = (request("page")-1)*perpage end if Mypagenum = page mystartline = startline getPageNum=array (Mypagenum, mystartline) end Function ' 參數:num ----------- 總數 ' perpage ------- 每頁條數 ' curr_page ----- 目前頁數,可以通過get 得到 ' mpurl --------- 目前網頁url,如:index.asp?op=Opp_add.asp ' '/ function multi(num, perpage, curr_page, mpurl,mytype) if(num > perpage) then page = 5 ' 設定顯示的數目 1 2 3 4 5 ....... or ...... 3 4 5 6 7 ..... offset = 2 ' Response.Write (curr_page-page+1) pages = num \ perpage '得到頁數 from = curr_page - offset '偏移兩頁 to_p = curr_page + page - offset - 1 if(page > pages) then from = 1 to_p = pages else if(from < 1) then to_p = curr_page + 1 - from from = 1 if((to_p - from) < page or (to_p - from) < pages) then to_p = page end if elseif(to_p > pages) then from = curr_page - pages + to_p to_p = pages if((to_p - from) < page or (to_p - from) < pages) then from = pages - page + 1 end if end if end if Select Case (mytype) case "0": fwd_back ="" fwd_back=fwd_back & "<form name=breakpage>共有 "&num&" 筆 | "&perpage&" 筆/頁| 目前第 "&curr_page&" 頁| " If(curr_page-page+1>=0) Then fwd_back=fwd_back & "<a href="""&mpurl&"&page=1"">|<<</a> " End if case "1": fwd_back = fwd_back & "<a href="""&mpurl&"&page=1"">|<<</a> " End Select for i = from to to_p+1 if(i <> int(curr_page)) then fwd_back = fwd_back & "<a href="""&mpurl&"&page="& i &""">["& i &"]</a> " else fwd_back = fwd_back & "<u><b>["&i&"]</b></u> " end if next if(pages > page and (pages+2-curr_page) >= page) then fwd_back = fwd_back & " <a href="""&mpurl&"&page="&pages+1&""">>>|</a> " end if multi = fwd_back end if end function %> '----------------------------------------------------------------------- ' index.asp <!-- #INCLUDE virtual="pageft.asp" --> <% '-------------------------------------分頁設定開始------------------------------------- 'query 跟 get_results 是我自己寫的開啟資料庫函式,小弟不提供方法,請大大們自行修正為自己開啟的方法 SET RSVAR = query("select count(*) from table") '取的資料庫中相對應的資料筆數 Myallpages = RSVAR(0) '設定所得筆數變數 Mypagesize = 8 '設定每頁筆數 myurl = "index.asp" '設定檔案連結,如自己已有所帶的參數亦可使用 index.asp?xxx=xxx GetPagestar = getPageNum(Mypagesize) ' GetPagestar(0) 為目前頁碼 GetPagestar(1) 為頁數起始點 mypagelist = multi(Myallpages,Mypagesize,GetPagestar(0),myurl,"0") 'mypagelist即為分頁變數、可直接印出測試 Response.write (mypagelist) SET RS = get_results ("select * from table limit "& GetPagestar(1) &","& Mypagesize &"") '-------------------------------------分頁設定結束------------------------------------- While Not RS.EOF '這邊自己寫,輸出的訊息 Wend %>
2011年5月12日 星期四
ASP的分頁範例
資料來源:http://www.blueshop.com.tw/board/show.asp?subcde=BRD20050926133403S2E&fumcde=&odr=cdt&odrtyp=0
訂閱:
張貼留言 (Atom)
沒有留言:
張貼留言