查詢翻頁(yè)優(yōu)化第2/2頁(yè)
更新時(shí)間:2006年09月30日 00:00:00 作者:
使用說(shuō)明
復(fù)制代碼 代碼如下:
Class cc_db_Pager
Public Property Let ConnectionString '//設(shè)置連接字符串
Public Property Set ActiveConnection(o) '//設(shè)置連接對(duì)象(與ConnectionString屬性二者取一)
Public Property Let TableName(s) '//設(shè)置查詢表名或視圖名
Public Property Let Fields(s) '//設(shè)置輸出字段名(可省略,默認(rèn)為"*",即所有字段)
Public Property Let Pkey(s) '//設(shè)置主鍵(可省略,默認(rèn)為"ID")
Public Property Let OrderBy(s) '//排序規(guī)則(可省略,省略則按默認(rèn)規(guī)則排序)
Public Property Let Page(s) '//設(shè)置當(dāng)前頁(yè)碼
Public Property Let PageSize(s) '//設(shè)置每頁(yè)記錄數(shù)
Public Property Let Sql(s) '//容錯(cuò)的SQL語(yǔ)句(此功能有待進(jìn)完善,暫保留)
Puvlic Property Get Sql '//返回已翻頁(yè)的SQL語(yǔ)句
Public Property Get RecordCount '//返回當(dāng)前記錄數(shù)
Public Property Get TotalRecordCoun '//返回總記錄數(shù)
Public Property Get Condition '//保留
Public Property Get PageCount '//返回總頁(yè)數(shù)
Public Property Get Recordset '//返回已分頁(yè)的記錄集(核心)
Public Property Get Version '//返回本段代碼的版本信息
Public Property Get Page '//返回當(dāng)前頁(yè)碼
Public Property Get AbsolutePage '//返回當(dāng)前頁(yè)(同上)
Public Function Information()
Private Function getSql()
Private Sub makeCondition()
Private Sub CaculateRecCount()
Private Sub CaculateTotalRecCount()
Private Sub CaculatePageCount()
Private Sub AddCondition(s)
Private Sub Class_Initialize()
Private Sub Class_Terminate()
End Class
使用方法演示
復(fù)制代碼 代碼如下:
<SCRIPT language="JavaScript">
function doPage(n){
location.href=location.pathname+'?page='+n+'&其他條件...';
}
</SCRIPT>
<%
Dim oDbPager
iPageSize = DefaultPageSize
Set oDbPager = New cc_db_Pager
Set oDbPager.ActiveConnection = oConn
oDbPager.TableName = "t_Company"
oDbPager.Fields = "ID,Company,WebSite,MainProduct,UserLevel, Status, Phone, Fax"
oDbPager.Pkey = "ID"
oDbPager.OrderBy = "UserLevel DESC, Status DESC, CharIndex('中國(guó)',Country) DESC, ID DESC"
oDbPager.PageSize = iPageSize
oDbPager.AddCondition "Status>0"
If Not isEmpty(Request.QueryString("Auth1")) Then
oDbPager.AddCondition "Auth1>0"
End If
oDbPager.Page = Request.QueryString("page")
iCurrPage = oDbPager.Page
iRecCount = oDbPager.RecordCount
iPageCount = oDbPager.PageCount
sPageInfo = "當(dāng)前頁(yè)為 "&iCurrPage&" 共計(jì) "&iPageCount&" 個(gè)頁(yè)面 共有 "&iRecCount&" 條信息"
sPager = "" & vbCrLf _
& "[<A "&IIf(CInt(iCurrPage)<=1,"disabled href='javascript:void(0);'","href='javascript:doPage(1);'")&">首頁(yè)</A>]" & vbCrLf _
& "[<A "&IIf(CInt(iCurrPage)<=1,"disabled href='javascript:void(0);'","href='javascript:doPage("&(iCurrPage-1)&");'")&">前頁(yè)</A>]" & vbCrLf _
& "[<A "&IIf(CInt(iCurrPage)>=CInt(iPageCount),"disabled href='javascript:void(0);'","href='javascript:doPage("&(iCurrPage+1)&");'")&">后頁(yè)</A>]" & vbCrLf _
& "[<A "&IIf(CInt(iCurrPage)>=CInt(iPageCount),"disabled href='javascript:void(0);'","href='javascript:doPage("&iPageCount&");'")&">末頁(yè)</A>]"
%>
...
<%
Set oRs = oDbPager.Recordset
Do While Not oRs.Eof
'// ...
oRs.MoveNext()
Loop
%>
...
<%=sPageInfo%>
...
<%=sPager%>
相關(guān)文章
一個(gè)簡(jiǎn)單的asp數(shù)據(jù)庫(kù)操作類
一個(gè)簡(jiǎn)單的asp數(shù)據(jù)庫(kù)操作類...2006-08-08Asp類 的數(shù)據(jù)庫(kù)領(lǐng)域
Asp類 的數(shù)據(jù)庫(kù)領(lǐng)域...2006-10-10實(shí)現(xiàn)支持邏輯搜索/單詞搜索/詞組搜索+支持OR/AND關(guān)鍵字的VBS CLASS!
實(shí)現(xiàn)支持邏輯搜索/單詞搜索/詞組搜索+支持OR/AND關(guān)鍵字的VBS CLASS!...2006-08-08