<!--#include file="conn.asp"-->
<%
"以下部分是驗證提交的page是否為合法的參數
"這部分最好判斷一下提交的參數是否為數值字符
dim page
page=Trim(request("page"))
If page="" Then
page=1
Elseif CInt(page)<=0 then
page=1
else
page=CInt(page)
End If
"進行查詢,取出要顯示的記錄
dim rs,sql,str
Set rs = Server.CreateObject("ADODB.Recordset")
sql="select * from a1"
rs.Open sql,conn,1,3
if Not rs.eof Then
str=rs("a1")
End If
rs.close
Set rs=nothing
"把出取來的記錄放入數組
dim strtmp
strtmp=Split((str),"<br>")
"取出要顯示的記錄,同時得到頁數
Dim n,tmp,i,j,tt
n=500
i=0
j=0
Do While i<=ubound(strtmp)
tmp=strtmp(i)
tt=true
Do While tt
If i>=ubound(strtmp) then
tt=false
j=j 1
elseif Len(tmp)>=n Then
tt=false
j=j 1
ElseIf Len(tmp) Len(strtmp(i 1))>=n Then
tt=false
j=j 1
Else
tmp=tmp "<br>" strtmp(i 1)
i=i 1
End If
Loop
if page=j then str=tmp "<br>"
i=i 1
Loop
"判斷傳送的參數是否越界,如果越界,則取得最後一頁的內容
if page>j then
str=tmp
end if
"顯示分頁內容
"注意傳遞的參數,這裡只傳遞了page,如果有其它參數要一起傳遞的,否則分頁後不顯示了
response.write "分頁——>"
For n=1 To j
if n=page then
response.write " "&n&" "
else
response.write "[<a href=index.asp?page="&n&">"&n&"</a>]"
end if
Next
response.write "<br><br>"
"顯示要分取出要顯示的這部分內容
response.write str
%>