查询翻页优化第2/2页
更新时间:2006年09月30日 00:00:00 作者:
使用说明
复制代码 代码如下:
Class cc_db_Pager
Public Property Let ConnectionString '//设置连接字符串
Public Property Set ActiveConnection(o) '//设置连接对象(与ConnectionString属性二者取一)
Public Property Let TableName(s) '//设置查询表名或视图名
Public Property Let Fields(s) '//设置输出字段名(可省略,默认为"*",即所有字段)
Public Property Let Pkey(s) '//设置主键(可省略,默认为"ID")
Public Property Let OrderBy(s) '//排序规则(可省略,省略则按默认规则排序)
Public Property Let Page(s) '//设置当前页码
Public Property Let PageSize(s) '//设置每页记录数
Public Property Let Sql(s) '//容错的SQL语句(此功能有待进完善,暂保留)
Puvlic Property Get Sql '//返回已翻页的SQL语句
Public Property Get RecordCount '//返回当前记录数
Public Property Get TotalRecordCoun '//返回总记录数
Public Property Get Condition '//保留
Public Property Get PageCount '//返回总页数
Public Property Get Recordset '//返回已分页的记录集(核心)
Public Property Get Version '//返回本段代码的版本信息
Public Property Get Page '//返回当前页码
Public Property Get AbsolutePage '//返回当前页(同上)
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
使用方法演示
复制代码 代码如下:
<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('中国',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 = "当前页为 "&iCurrPage&" 共计 "&iPageCount&" 个页面 共有 "&iRecCount&" 条信息"
sPager = "" & vbCrLf _
& "[<A "&IIf(CInt(iCurrPage)<=1,"disabled href='javascript:void(0);'","href='javascript:doPage(1);'")&">首页</A>]" & vbCrLf _
& "[<A "&IIf(CInt(iCurrPage)<=1,"disabled href='javascript:void(0);'","href='javascript:doPage("&(iCurrPage-1)&");'")&">前页</A>]" & vbCrLf _
& "[<A "&IIf(CInt(iCurrPage)>=CInt(iPageCount),"disabled href='javascript:void(0);'","href='javascript:doPage("&(iCurrPage+1)&");'")&">后页</A>]" & vbCrLf _
& "[<A "&IIf(CInt(iCurrPage)>=CInt(iPageCount),"disabled href='javascript:void(0);'","href='javascript:doPage("&iPageCount&");'")&">末页</A>]"
%>
...
<%
Set oRs = oDbPager.Recordset
Do While Not oRs.Eof
'// ...
oRs.MoveNext()
Loop
%>
...
<%=sPageInfo%>
...
<%=sPager%>
相关文章
实现支持逻辑搜索/单词搜索/词组搜索+支持OR/AND关键字的VBS CLASS!
实现支持逻辑搜索/单词搜索/词组搜索+支持OR/AND关键字的VBS CLASS!...2006-08-08
最新评论