指定页的访问。好象很并不复杂呀,下面让我们来看看
程序该如何实现呢?
我们建立这样一个简单的 BBS 应用程序,它的数据库中分别有以下五个字段:“ID”,每个帖子的自动编号;“subject”,每个帖子的主题;“name”,加帖用户的姓名;“email”,用户的电子邮件地址;“postdate”,加帖的时间。数据库的 DSN 为“bbs”。我们将显示帖子分页的所有步骤放在一个名为“ShowList()”的过程中,方便调用。
程序如下:
----BBS 显示帖子分页----
$#@60; % Sub ShowList() %$#@62;
$#@60; %
PgSz=20 设定开关,指定每一页所显示的帖子数目,默认为20帖一页
Set Conn = Server.CreateObject("ADODB.Connection")
Set RS = Server.CreateObject("ADODB.RecordSet")
sql = "SELECT * FROM message order by ID DESC"
查询所有帖子,并按帖子的ID倒序排列
Conn.Open "bbs"
RS.open sql,Conn,1,1
If RS.RecordCount=0 then
response.write "$#@60; P$#@62;$#@60; center$#@62;对不起,数据库中没有相关信息!$#@60; /center$#@62;$#@60; /P$#@62;"
else
RS.PageSize = Cint(PgSz) 设定PageSize属性的值
Total=INT(RS.recordcount / PgSz * -1)*-1 计算可显示页面的总数
PageNo=Request("pageno")
if PageNo="" Then
PageNo = 1
else
PageNo=PageNo+1
PageNo=PageNo-1
end if
ScrollAction = Request("ScrollAction")
if ScrollAction = " " Then
PageNo=PageNo-1
end if
if ScrollAction = " " Then
PageNo=PageNo+1
end if
if PageNo $#@60; 1 Then
PageNo = 1
end if
n=1
RS.AbsolutePage = PageNo
Response.Write "$#@60; CENTER$#@62;"
position=RS.PageSize*PageNo
pagebegin=position-RS.PageSize+1
if position $#@60; RS.RecordCount then
pagend=position
else
pagend= RS.RecordCount
end if
Response.Write "$#@60; P$#@62;$#@60; font color=Navy$#@62;$#@60; B$#@62;数据库查询结果:$#@60; /B$#@62;"
Response.Write "(共有"&RS.RecordCount &"条符合条件的信息,显示"&pagebegin&"-"&pagend&")$#@60; /font$#@62;$#@60; /p$#@62;"
Response.Write "$#@60; TABLE WIDTH=600 BORDER=1 CELLPADDING=4 CELLSPACING=0 BGCOLOR=#FFFFFF$#@62;"
Response.Write "$#@60; TR BGCOLOR=#5FB5E2$#@62;$#@60; FONT SIZE=2$#@62;$#@60; TD$#@62;$#@60; B$#@62;主题$#@60; /B$#@62;$#@60; /TD$#@62;$#@60; TD$#@62;$#@60; B$#@62;用户$#@60; /B$#@62;$#@60; /TD$#@62;$#@60; TD$#@62;$#@60; B$#@62;Email$#@60; /B$#@62;$#@60; /TD$#@62;$#@60; TD$#@62;$#@60; B$#@62;发布日期$#@60; /B$#@62;$#@60; /TD$#@62;$#@60; /FONT$#@62;$#@60; TR BGCOLOR=#FFFFFF$#@62;"
Do while not (RS is nothing)
RowCount = RS.PageSize
Do While Not RS.EOF and rowcount $#@62; 0
If n=1 then
Response.Write "$#@60; TR BGCOLOR=#FFFFFF$#@62;"
ELSE
Response.Write "$#@60; TR BGCOLOR=#EEEEEE$#@62;"
End If
n=1-n %$#@62;
$#@60; TD$#@62;$#@60; span style="font-size:9pt"$#@62;$#@60; A href=view.asp?key=$#@60; % =RS("ID")%$#@62;$#@62;$#@60; % =RS("subject")%$#@62;$#@60; /A$#@62;$#@60; /span$#@62;$#@60; /td$#@62;
$#@60; TD$#@62;$#@60; span style="font-size:9pt"$#@62;$#@60; % =RS("name")%$#@62;$#@60; /A$#@62;$#@60; /span$#@62;$#@60; /td$#@62;
$#@60; TD$#@62;$#@60; span style="font-size:9pt"$#@62;$#@60; a href="mailto:$#@60; % =RS("email")%$#@62;"$#@62;$#@60; % =RS("email")%$#@62;$#@60; /a$#@62;$#@60; /span$#@62; $#@60; /TD$#@62;
$#@60; TD$#@62;$#@60; span style="font-size:9pt"$#@62;$#@60; % =RS("postdate")%$#@62;$#@60; /spa