目的:
为多条纪录分页显示
起因:
当符合选取的纪录过多时,若不分页,那这一页将显示得很长,若是用“猫”上网的用户遇到这个页面还不知道得等多久才能看到,因此,我们可以分页显示这些纪录。
解决方案:
下面以本站Article.asp?BoardID=2为例来说明
<%on error resume next
Dim dbc,rs,sql,Mypage,pageno,tsum,RowCount,NextPage,PrwePage
Set dbc = Server.CreateObject("ADODB.Connection")
dbc.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source="&"您的数据库名.mdb;"&"Jet OLEDB:Database Password=您的密码" '在这里更换成您的数据库和密码
Set rs=server.createobject("ADODB.RECORDSET")
sql= "Select * From 您的表名"
rs.open sql,dbc,1,1
Mypage =20 '设置每页显示多条留言
if rs.bof and rs.eof then
response.write ("对不起,没有这一页,请<a href='#' onClick='history.go(-1)' target='_self'>返回</a>!")
Response.End
else
rs.pagesize=INT(Mypage)
PageNo=REQUEST("PageNo")
if pageno="" or pageno="0" then
pageno=1
end if
if PageNo<0 then
response.write ("对不起,没有这一页,请<a href='#' onClick='history.go(-1)' target='_self'>返回</a>!")
Response.End
End if
RS.AbsolutePage=PageNo
TSum=INT(rs.RECORDCOUNT/Mypage*-1)*-1
RowCount=rs.PageSize
if PageNo="" or PageNo=0 then
PageNo=1
else
PageNo=PageNo+1
PageNo=PageNo-1
end if
if CINT(PageNo)>1 and CINT(PageNo)>CINT(TSum) then
response.write ("对不起,没有这一页,请<a href='#' onClick='history.go(-1)' target='_self'>返回</a>!")
Response.End
end if
end if%>
<tr>
<td width="600" valign="baseline" colspan="6">
文章数:<%=rs.RECORDCOUNT%>
页数:<font color=red><%=PageNo%></font>/<%=TSum%> <%=PageList%>
</td></tr>
<tr>
<td width="600" height=1 valign="top" colspan="6">
<hr size="1" color="#D6DB94"></td>
</tr>
<tr bgcolor="#FF99FF">
<td width="60"><font color="#6600CC">所属分类</font></td>
<td width="300"><font color="#6600CC">文章标题</font></td>
<td width="80" align="center"><font color="#6600CC">作者</font></td>
<td width="50" align="center"><font color="#6600CC">发表日期</font></td>
<td width="40" align="center"><font color="#6600CC">大小</font></td>
<td width="25"><font color="#6600CC">人气</font></td>
</tr>
<% Do while not rs.eof AND RowCount>0%>
<tr bgcolor="#FF99FF">
<td width="60"><font color="#6600CC">所属分类</font></td> '这里换成你的显示结果
<td width="300"><font color="#6600CC">文章标题</font></td>
<td width="80" align="center"><font color="#6600CC">作者</font></td>
<td width="50" align="center"><font color="#6600CC">发表日期</font></td>
<td width="40" align="center"><font color="#6600CC">大小</font></td>
<td width="25"><font color="#6600CC">人气</font></td>
</tr>
<% RowCount=RowCount-1
rs.Movenext%>
<% Loop%>
</table>
</td>
</tr>
</table>
<%rs.close
Set rs=nothing
dbc.close
Set dbc = Nothing%>
</body>
</html>
<%function PageList()
if TSum>1 then
if PageNo=1 then
NextPage=PageNo+1
response.write "上一页 |"
response.write" <a href='Article.asp?label="&label&"&PageNo="&NextPage&"' target='_self' title='看看后面还有没有什么好东东'>下一页</a>"
end if
if PageNo=TSum then
PrwePage=PageNo-1
response.write "<a href='Article.asp?label="&label&"&PageNo="&PrwePage&"' target='_self' title='上页还没看完?返回吧'>上一页</a> |"
response.write" 下一页"
end if
if PageNo>1 and TSum>PageNo then
NextPage=PageNo+1
PrwePage=PageNo-1
response.write "<a href='Article.asp?label="&label&"&PageNo="&PrwePage&"' target='_self' title='上页还没看完?返回吧'>上一页</a> |"
response.write" <a href='Article.asp?label="&label&"&PageNo="&NextPage&"' target='_self' title='看看后面还有没有什么好东东'>下一页</a>"
end if
end if
End function%>
*****************************
演示地址Article.asp?BoardID=2