给你这样一个分页完全代码,你照着改改就行了,用着非常方便。
========================================
<%
Const MaxPerPage=17
dim totalPut
dim CurrentPage
dim TotalPages
dim i,j
dim sql
dim rs
if Not isempty(request("page")) then
currentPage=Cint(request("page"))
else
currentPage=1
end if
Set rs= Server.CreateObject("adodb.recordset")
sql="Select * from news order by publishdate desc"
rs.open sql,conn,1,1
if err.number<>0 then
response.write "数据库中无数据"
end if
if rs.eof And rs.bof then
Response.Write "<p align='center' class='contents'> 对不起,暂时没有任何新闻!</p>"
else
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,"allnews.asp"
else
if (currentPage-1)*MaxPerPage<totalPut then
rs.move (currentPage-1)*MaxPerPage
dim bookmark
bookmark=rs.bookmark
showContent
showpage totalput,MaxPerPage,"allnews.asp"
else
currentPage=1
showContent
showpage totalput,MaxPerPage,"allnews.asp"
end if
end if
rs.close
end if
Set rs=Nothing
conn.close
Set conn=nothing
sub showContent
dim i
i=0
%>
<table width="96%" border="0" align="center" cellspacing="4" cellpadding="0">
<%Do While Not rs.eof%>
<tr>
<td width="90%" height="20" class="contents"><A href="javascript:openwin(<%=rs("id")%>)">□
<%=rs("title")%></a></td>
<td height="20" nowrap class="contents"><%=formatdatetime(rs("publishdate"),yyyy-mm-dd)%></td>
</tr>
<%
i=i+1
if i>=MaxPerPage then Exit Do
rs.movenext
Loop
%>
</table>
<%
End Sub
Function showpage(totalnumber,maxperpage,filename)
Dim n
If totalnumber Mod maxperpage=0 Then
n= totalnumber \ maxperpage
Else
n= totalnumber \ maxperpage+1
End If
Response.Write "<form method=Post action="&filename&">"
Response.Write "<p align='center' class='contents'> "
If CurrentPage<2 Then
Response.Write "<font class='contents'>首页 上一页</font> "
Else
Response.Write "<a href="&filename&"?page=1 class='contents'>首页</a> "
Response.Write "<a href="&filename&"?page="¤tPage-1&" class='contents'>上一页</a> "
End If
If n-currentpage<1 Then
Response.Write "<font class='contents'>下一页 尾页</font>"
Else
Response.Write "<a href="&filename&"?page="&(CurrentPage+1)&" class='contents'>"
Response.Write "下一页</a> <a href="&filename&"?page="&n&" class='contents'>尾页</a>"
End If
Response.Write "<font class='contents'> 页次:</font><font class='contents'>"¤tPage&"</font><font class='contents'>/"&n&"页</font> "
Response.Write "<font class='contents'> 共"&totalnumber&"条记录 "&maxperpage&"条记录/页</font> "
Response.Write "<font class='contents'>转到:</font><input type='text' name='page' size=4 maxlength=10 class=smallInput value="¤tpage&">"
Response.Write "<input type='submit' class='contents' value='转到' name='cndok'></form>"
End Function
%>
你想怎么分页?
用ASP的分页功能不就行了,按你的条件Select ,然后用Recordset的分页属性就可以了
RSCount=RS.RecordCount
pgsz=20
IF RSCount> 0 Then
i=1
RS.PageSize=pgsz ‘每页显示的记录
Total=Int(RSCount/pgsz*-1)*-1 '页数
PageNo=Request.QueryString("page") 当前页
RS.AbsolutePage = PageNo
position=RS.PageSize*PageNo
pagebegin=position-RS.PageSize+1
if position <RS.RecordCount then
pagend=position
else
pagend= RSCount
end if
RowCount=RS.Pagesize
Do while NOT RS.EOF and RowCount>0
。。。。。
RowCount=RowCount-1
RS.MoveNext
loop
end if