分頁顯示函式

2022-09-06 00:15:27 字數 3135 閱讀 3939

<%'簡單分頁,兩次讀庫操作

dim ts_id,ts_table,ts_field,ts_order

ts_id="id"  '索引id

ts_table="table1" '表名

ts_field="id,aaaa,bbbb,cccc" '欄位名

ts_order="order by id desc"   '倒序

dim ts_page_count,ts_page_per,ts_page_cnts,page

ts_page_per=5 '每頁顯示數

ts_page_cnts=4  '每頁顯示的頁數

page = request.querystring("page") '得到當前頁碼

if page="" or not isnumeric(page) then page=1

page =int(page)

'從資料庫中讀取統計當前記錄總數

set rs=server.createobject("adodb.recordset")

'sql= "select count("&ts_id&") from "&ts_table&" "

'rs.open sql,conn,0,1,&h0001

'ts_page_count = rs(0)

'rs.close

ts_page_count=conn.execute("select count("&ts_id&") from "&ts_table&" ",0,1)(0)

' 顯示頁碼的函式

function ts_pagefun(ts_page_count)

dim ts_page_k,ts_page_pagecnt,ts_page_page2

'計算頁數

if ts_page_count/ts_page_per = int(ts_page_count/ts_page_per) then

ts_page_pagecnt=int(ts_page_count/ts_page_per)

else

ts_page_pagecnt=int(ts_page_count/ts_page_per)+1

end if

'最大分頁

if page>ts_page_pagecnt then page=ts_page_pagecnt '

ts_page_page2= int(page/ts_page_cnts)

if page/ts_page_cnts>ts_page_page2 then ts_page_page2=ts_page_page2+1

ts_page_k=ts_page_page2*ts_page_cnts

if ts_page_k>ts_page_pagecnt then ts_page_k=ts_page_pagecnt              

'打出頁碼

response.write ("有"&ts_page_count&" 條 "& page &"/"& ts_page_pagecnt &"頁 分頁")

if ts_page_page2>1 then

response.write ("9

")response.write (" 3

")end if

for ts_page_m =ts_page_page2*ts_page_cnts-(ts_page_cnts-1) to ts_page_k

response.write (" ["& ts_page_m &"]")

next

if ts_page_page2*ts_page_cnts < ts_page_pagecnt then

response.write (" 4

")response.write (" :

")end if

end function

' 顯示頁碼的函式

function ts_pageturn(ts_page_count)

dim ts_page_pagecnt,startpage,endpage

'計算頁數

if ts_page_count/ts_page_per = int(ts_page_count/ts_page_per) then

ts_page_pagecnt=int(ts_page_count/ts_page_per)

else

ts_page_pagecnt=int(ts_page_count/ts_page_per)+1

end if            

'打出頁碼

response.write (""&vbcrlf)

response.write ("共"&ts_page_count&"條 "& page &"/"& ts_page_pagecnt &"頁")

if page>1 then

response.write ("首頁

"&vbcrlf)

response.write ("尾頁

'開啟記錄集

sql="select  "&ts_field&" from "&ts_table&" "&ts_order&" "

rs.open sql,conn,1,1,&h0001

'根據分頁引數獲取當前頁面紀錄

rs.absoluteposition=rs.absoluteposition+((abs(page)-1)*ts_page_per)

%>

<%=ts_pageturn(ts_page_count)%>

<%

ipage=0

do while not rs.eof and ipage < ts_page_per

ipage=ipage+1

response.write(rs("aaaa")&"

")%>

<%

rs.movenext

loop

rs.close '每用完一次rs,就關一次

'每頁最後,關閉和釋放記憶體

set rs = nothing

conn.close

set conn=nothing

%>

<%

endtime=timer

response.write "

執行時間"&(endtime-startime)*1000&"毫秒

"%>

長文章分頁顯示函式

public string nohtml string htmlstring 去除html標記 else if request.querystring pages null catch set the page content 設定獲取當前頁的大小 if m intcurrentpage m int...

使用popen函式實現分頁顯示

include include include apue.h include include include include include include define pager int main int argc char argv if ferror fpin err sys fgets e...

oracle分頁顯示

oracle中rownum表示行號,比如你想返回前10行,sql如下 select from mytable where rownum 10 如果返回90 100行,那行下面的語句是不對的 select from mytable where rownum 90 and rownum 100 orac...