asp示例:
详细示例:
<%
'获取页数
num=cint(request("num"))
response.Write cint(5.4)
set con=server.CreateObject ("adodb.connection")
con.ConnectionString="Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Initial Catalog=master;Data Source=n211/a"
con.Open
'总页数 以每页10条记录分页,最后有可能出现不免够10条记录的情况,而cint会四舍五入,所以分两种情况人工处理
'每页显示10个超链接
if num=0 then '当用户初次打开网页时,没有点击任何页所以num=0
set rs2=server.CreateObject ("adodb.recordset")
rs2.Open "select * from sysobjects",con,3
'余数大于等于5
if (rs2.RecordCount mod 10)>=5 then
session("PAGEcount")=cint(rs2.RecordCount/10)
else
'余数小于5
session("PAGEcount")=cint(rs2.RecordCount/10)+1
end if
response.Write session("PAGEcount")
set rs2=nothing
'起始页
session("begin")=0
'结束页
session("endd")=10
num=1
end if
'主要
str=cint(session("begin"))
ed=cint(session("endd"))
'递增页数的时机
'用户点击首页及尾页超链接时,才进行翻页处理
if num<cint(session("PAGEcount")) and (num mod 10 = 0) then
'点击首页
if num=cint(session("begin")) then
response.Write "str" & str
response.Write "num" & num
str=str-10
ed=ed-10
end if
'点击尾页
if num=cint(session("endd")) then
response.Write "ed" & ed
str=str+10
ed=ed+10
end if
'重新初始化首尾页起点
session("begin")=str
session("endd")=ed
end if
'所要查询的现记录起点
number=(num-1)*10
'数据库分页:当有10万条记录时,用户可能只需查看第30--40条的记录,而这时变通的select语句
'会把所有记录全部倒入内存,是严重的资源消费,所以使用以下的子查询语句,每次只显示
'用户需要的10条记录
'例如有30条记录,子查询为top 10,则子查询结果为所以记录的前10条,父查询则为除了这10条之外的头10条
'即11-20条
set rs=server.CreateObject("adodb.recordset")
rs.Open "select top 10 * from sysobjects where id not" _
& " in (select top " & number & " id from dbo.sysobjects order by id)order by id ",con,3
rs.MoveFirst
%>
<form action="page.asp" method="post">
<table border =1 bgcolor=#33ff99>
<tr bgcolor=#00cccc>
<%
for i=0 to rs.Fields.Count-1
%>
<!--列头-->
<td><font color=#ffff33><%=rs.Fields(i).name%></font></td>
<%
next
%>
</tr>
<% for i=0 to rs.RecordCount-1%>
<tr bgcolor=#ffff33>
<!--内容-->
<td><font color=#006600><%=rs.Fields(0)%></font></td>
<td><font color=#006600><%=rs.Fields(1)%></font></td>
<td><font color=#006600><%=rs.Fields(2)%></font></td>
<td><font color=#006600><%=rs.Fields(3)%></font></td>
<td><font color=#006600><%=rs.Fields(4)%></font></td>
<td><font color=#006600><%=rs.Fields(5)%></font></td>
<td><font color=#006600><%=rs.Fields(6)%></font></td>
<td><font color=#006600><%=rs.Fields(7)%></font></td>
<td><font color=#006600><%=rs.Fields(8)%></font></td>
<td><font color=#006600><%=rs.Fields(9)%></font></td>
<td><font color=#006600><%=rs.Fields(10)%></font></td>
<td><font color=#006600><%=rs.Fields(11)%></font></td>
<td><font color=#006600><%=rs.Fields(12)%></font></td>
<td><font color=#006600><%=rs.Fields(13)%></font></td>
<td><font color=#006600><%=rs.Fields(14)%></font></td>
<td><font color=#006600><%=rs.Fields(15)%></font></td>
<td><font color=#006600><%=rs.Fields(16)%></font></td>
<td><font color=#006600><%=rs.Fields(17)%></font></td>
<td><font color=#006600><%=rs.Fields(18)%></font></td>
<td><font color=#006600><%=rs.Fields(19)%></font></td>
<td><font color=#006600><%=rs.Fields(20)%></font></td>
<td><font color=#006600><%=rs.Fields(21)%></font></td>
<td><font color=#006600><%=rs.Fields(22)%></font></td>
<td><font color=#006600><%=rs.Fields(23)%></font></td>
<td><font color=#006600><%=rs.Fields(24)%></font></td>
</tr>
<%
rs.MoveNext
if rs.EOF then rs.MoveLast
next
%>
</table>
<%
begin=cint(session("begin"))
endd=cint(session("endd"))
if begin=0 then begin=1
'ruguowei
if endd>session("PAGEcount") then endd=session("PAGEcount")
for i=begin to endd
%>
<a href ="page.asp?num=<%=i%>"><%=i%></a>
<%
next
%>
</form>
简单示例:
<!--分页技术-->
<%
'记录总数
mypagecount=80
pageS=CINT(request("page"))
response.Write pageS
if pageS<=0 THEN
pageS=1
'开始值
session("begin")=0
'结束值
session("endd")=10
END IF
statrP=cint(session("begin"))
endP=cint(session("endd"))
if (pageS < mypagecount) and (pageS MOD 10 = 0) THEN
'上翻页
if pageS=cint(session("begin")) then
statrP=statrP-10
endP=endP-10
end if
'下翻页
if pageS=cint(session("endd")) then
statrP=statrP+10
endP=endP+10
end if
session("begin")=statrP
session("endd")=endP
END IF
begin=cint(session("begin"))
endd=cint(session("endd"))
if begin=0 then begin=1
if endd > mypagecount then endd = mypagecount
for i=begin to endd
%>
<a href="asp.asp?page=<%=i%>"><%=i%></a>
<%
next
%>