我写的分页类
1 只取需要得数据 sql最优化
2 可以排序
3 速度最快
4 史上最好 呵呵
5 用用就知道了!
<!--#include file="conn.asp"-->
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<%
'/////////////////转载请注明---本类由withtao 维护////////////////////////
'/////////////////超强的asp分页类/////////////////////////////////////////////////////////////////////
Call ceshi
Sub ceshi()
dim p
set p = New divp
p.item = Array("did","mp","ddate","txt","flag","part")
p.item2 = Array("","","","","","")
p.sql = " from mrecord,perday where perday.phone=mrecord.mp"
p.item1 = Array("did","手机号","定制时间","类型","状态","时间段")
p.url=" "
p.MaxPerPage = 20
p.init
set p = nothing
'p.sql = "SELECT COUNT(dstate) AS num, dstate FROM muser GROUP BY dstate"
'p.item = Array("dstate","num")
'p.item = Array("id","rnd")
'p.item1 = Array("ID","保护码")
'p.sql = "SELECT * FROM rnd"
End sub
'////////////////////////////////////////////////////////////
Class divp
dim item,item1,item2
dim url
dim px,desc
dim totalPut 'all records
dim CurrentPage 'current page NO.
dim TotalPages 'total pages
dim i,j
dim sql,sql1
dim rs,rs1
dim rstype
dim typesql
dim MaxPerPage
dim pp
Sub initsql()
px = request.Form("px")
desc = cint(request.Form("desc"))
px = replace(px,"'","")
pp = request.Form("page")
if not isempty(pp) then 'the value when click next page input
currentPage = clng(request.Form("page"))
if currentPage = 0 then
currentPage = clng(request.Form("page")) '设置当前页码
end if
else
currentPage = 1
end if
sql1 = "select count(*) as num" & sql
sql = "select top " & currentPage * MaxPerPage & " * " & sql
if px = "" then px = item(0)
sql = sql & " order by " & px
url = "?px=" & px
'response.Write "-------" & desc & "------------"
if isempty(item1) then item1 = item
if desc = 1 then '/////////fanxu反序///////////////////////////////////////////////////////
sql = sql & " DESC"
sql = "select * from (select top " & MaxPerPage &" * from (" & sql & ") tb1 order by " & px & " ) tb2 order by " & px & " desc"
'url = "?px=" & px & "&desc=1"
else'//////////////正序///////////////////////////////////////////////////////////////////////
sql = "select * from (select top " & MaxPerPage &" * from (" & sql & ") tb1 order by " & px & " desc ) tb2 order by " & px
end if
end sub
'Sub Class_Initialize()
Sub init()
call initsql()
'const MaxPerPage = 20 'NO.of record per page
'//////////////////////////////////////////////////////////////////////////////
response.Write "<------" & sql & "---------->"
Set rs = Server.CreateObject("ADODB.Recordset")
on error resume next
rs.open sql,conn,1,1
if err.num > 0 then
px = item(0)
err.clear
rs.open sql,conn,1,1
end if
'//////////////////////////////////////////////////////////////////////////
rs1 = conn.execute(sql1)
'response.Write rs1("num") & "--------------"
'//////////////////////////////////////////////////////////////////////////
if rs.eof and rs.bof then
response.write "<p align='center'> 还没有任何东西</p>"
else
totalPut = rs1("num")
'totalPut=rs.recordcount
'**********************
if currentpage < 1 then
currentpage = 1
end if
'/////////////////////////////////////////////////////
if (currentpage - 1) * MaxPerPage > totalput then '即最后一页不满
if (totalPut mod MaxPerPage) = 0 then '正好除尽的情况
currentpage = totalPut \ MaxPerPage
else
currentpage = totalPut \ MaxPerPage + 1
end if
end if
'/////////////////////////////////////////////////
if currentPage = 1 then
showContent
showpage totalput,MaxPerPage',url
else
if (currentPage - 1)*MaxPerPage < totalPut then
'rs.move (currentPage-1) * MaxPerPage
'dim bookmark
'bookmark = rs.bookmark
showContent
showpage totalput,MaxPerPage',url
else
currentPage = 1
showContent
showpage totalput,MaxPerPage',url
end if
end if
'////////////////////////////////////////////////////////////////////
end if
End sub
Sub Class_terminate()
'//////////////////////////////////////////////////////////////////////////
'rs.close
set rs = nothing
'conn.close
set conn = nothing
End sub
'////////////////////循环次数由 每页最多条 控制//////////////////////////
Sub showContent()
dim i
i = 0
%>
<style type="text/css">
<!--
body{
font-size: 13px;
line-height: 16px;
}
.s1 {
font-size: 13px;
line-height: 16px;
}
#AutoNumber1 a:link {
color: #FFFFFF;
}
#AutoNumber1 a {
text-decoration: none;
}
#AutoNumber1 a:visited {
color: #FFFFFF;
}
-->
</style>
<table border="0" align="center" cellpadding="3" cellspacing="1" bgcolor="#CCCCCC" class="s1" id="AutoNumber1" style="border-collapse: collapse" >
<tr bgcolor="#0066CC">
<% for p = 0 to ubound(item1) %>
<td align="center" >
<font color="#FFFFFF">
<a href="#" onclick="js:sethide1('px','<%= item2(p) %><%= item(p) %>');sethide('desc','0');">↓</a>
<%= item1(p) %>
<a href="#" onclick="js:sethide1('px','<%= item2(p) %><%= item(p) %>');sethide('desc','1');">↑</a>
</font></td>
<% next %>
<!-- <td ><font color="#FFFFFF">删除</font></td> -->
</tr>
<% do while not rs.eof %>
<tr bgcolor="eeeeee">
<% for p = 0 to ubound(item) %>
<td align="center"><%= rs(item(p))%> </td>
<% next %>
<!-- <td align="center"><a href="del.asp?did=<%= rs(item(0))%>" onclick="return confirm('想好了?删不?');">删除</a> </td> -->
</tr>
<%
i = i + 1
if i >= MaxPerPage then exit do
rs.movenext
loop
%>
</table>
<% End sub
'显示页码,和翻页的函数
'Function showpage(totalnumber,maxperpage,filename)
Function showpage(totalnumber,maxperpage)
dim n 'n是总页面数 计算出来 用取整的方法
if totalnumber mod maxperpage = 0 then
n = totalnumber \ maxperpage
else
n = totalnumber \ maxperpage+1
end if
%>
<!-- 提交的是页码 -->
<div align='center'>
<form action="" method="post" name="from2" id="from2">
<%
px = request.Form("px")
if CurrentPage < 2 then '首页
response.write "<font color='#000080'>首页 上一页</font> "
else
%>
<a href='#' onclick="js:sethide('page','1');">首页</a>
<a href='#' onclick="js:sethide('page','<%= CurrentPage - 1 %> ');">上一页</a>
<%end if
if n - currentpage < 1 then '尾页
response.write "<font color='#000080'>下一页 尾页</font>"
else
%>
<a href='#' onclick="js:sethide('page','<%= ( CurrentPage + 1 ) %>');">下一页</a>
<a href='#' onclick="js:sethide('page','<%= n %>');">尾页</a>
<% end if
%>
<font color='#000080'> 页次:</font><strong><font color='red'><%= CurrentPage %></font></strong><font color='#000080'><strong>/<%= n %></strong>页</font>
<font color='#000080'> 共<b><%= totalnumber %></b>条record <b><%= maxperpage %></b>条record/页</font>
<font color='#000080'>转到:</font>
<input type='text' name='page' size='6' maxlength='10' class='smallInput' value='<%= currentpage %>'>
<input name='queding' type="submit" id="queding" value="确定" >
<input name="px" type="hidden" id="px" value="<%= px %>" />
<input name="desc" type="hidden" id="desc" value="<%= desc %>" />
</form>
</div>
<script language="JavaScript" type="text/javascript">
function sethide1(id,vl){
eval('document.from2.'+id+'.value="'+vl+'"');
//from2.submit();
}
function sethide(id,vl){
eval('document.from2.'+id+'.value="'+vl+'"');
//var p = confirm(" sure ?");
//alert(p);
//if (p)
//{
from2.submit()};
//}
</script>
<%
End function
End class
%>