子的自動編號;“s我們建立這樣一個簡單的BBS應用程序,它的數據庫中分別有以下五個字段:“ID”,每個帖ubject”,每個帖子的主題;“name”,加帖用戶的姓名;“email”,用戶的電子郵件地址;“postdate”,加帖的時間。數據庫的DSN為“bbs”。我們將顯示帖子分頁的所有步驟放在一個名為“ShowList()”的過程中,方便調用。程序如下: '----BBS顯示帖子分頁---- <% Sub ShowList() %> <% 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 "<P><center>對不起,數據庫中沒有相關信息!</center></P>" 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 <1 Then PageNo = 1 end if n=1 RS.AbsolutePage = PageNo Response.Write "<CENTER>" position=RS.PageSize*PageNo pagebegin=position-RS.PageSize+1 if position <RS.RecordCount then pagend=position else pagend= RS.RecordCount end if Response.Write "<P><font color='Navy'><B>數 據 庫 查 詢 結 果:</B>" Response.Write "(共有"&RS.RecordCount &"條符合條件的信息,顯示"&pagebegin&"-"&pagend&")</font></p>" Response.Write "<TABLE WIDTH=600 BORDER=1 CELLPADDING=4 CELLSPACING=0 BGCOLOR=#FFFFFF>" Response.Write "<TR BGCOLOR=#5FB5E2><FONT SIZE=2><TD><B>主 題</B></TD><TD><B>用 戶</B></TD><TD><B>Email</B></TD><TD><B>發 布 日 期</B></TD></FONT><TR BGCOLOR=#FFFFFF>" Do while not (RS is nothing) RowCount = RS.PageSize Do While Not RS.EOF and rowcount > 0 If n=1 then Response.Write "<TR BGCOLOR=#FFFFFF>" ELSE Response.Write "<TR BGCOLOR=#EEEEEE>" End If n=1-n %> <TD><span style="font-size:9pt"><A href='view.asp?key=<% =RS("ID")%>'><% =RS("subject")%></A></span></td> <TD><span style="font-size:9pt"><% =RS("name")%></A></span></td> <TD><span style="font-size:9pt"><a href="mailto:<% =RS("email")%>"><% =RS("email")%></a></span> </TD> <TD><span style="font-size:9pt"><% =RS("postdate")%></span> </td> </TR> <% RowCount = RowCount - 1 RS.MoveNext Loop set RS = RS.NextRecordSet Loop Conn.Close set rs = nothing set Conn = nothing %> </TABLE> <FORM METHOD=GET ACTION="list.asp"> <INPUT TYPE="HIDDEN" NAME="pageno" VALUE="<% =PageNo %>"> <% if PageNo > 1 Then response.write "<INPUT TYPE=SUBMIT NAME='ScrollAction' VALUE=' 上一頁 '>" end if if RowCount = 0 and PageNo <>Total then response.write "<INPUT TYPE=SUBMIT NAME='ScrollAction' VALUE=' 下一頁 '>" end if response.write "</FORM>" End if %> <% End Sub %>