求助:ASP关于分页的问题
发布网友
发布时间:2023-07-12 02:22
我来回答
共4个回答
热心网友
时间:2024-11-26 11:21
<%
Set Rsf=Server.CreateObject("adodb.recordSet")
Sql="Select top 100 * from wenzhang where yanzheng='ok' order by id desc"
Rsf.open Sql,conn,1,1
If Rsf.bof and Rsf.eof then
response.write "<tr><td height=50 align=center>暂时没有新闻文章</td></tr>"
else
rsf.pageSize = 30 '每页记录数
allPages = rsf.pageCount '总页数
page = Request("page") '从浏览器取得当前页
'if是基本的出错处理
If not isNumeric(page) then page=1
if isEmpty(page) or clng(page) < 1 then
page = 1
elseif clng(page) >= allPages then
page = allPages
end if
rsf.AbsolutePage = page '转到某页头部
For i=1 To rsf.pageSize
If rsf.eof Then Exit for
%>
<table width="930" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td width="120" rowspan="3" align="center" valign="middle" bgcolor="#FFFFFF">
<img src="<%=Rsf("imgurl")%>" alt="<%=Rsf("url")%>" width=88 height=31 border=0〉
</td>
<td height="22" colspan="2" bgcolor="#FFFFFF"><a href="<%=Rsf("url")%>"
target="_blank"><b><%=Rsf("site")%></b></a>-<%=Rsf("readme")%></td>
</tr>
<tr>
<td height="15" colspan="2" valign="top" bgcolor="#FFFFFF"> <font color=#666666>·
<em><%=Rsf("url")%> <%=Rsf("add")%></em></font><br><br></td>
</tr>
</table>
</TD>
</TR>
</TABLE>
<%
rsf.movenext
next
call listpage()
End If
%>
<%
sub listpage()
'if allpages<=1 then exit sub
response.write "<tr><td height=30> </td></tr>"
response.write "<tr><td align=center>"
response.write "<br>总计 "&RSf.RecordCount&" 篇文章 "
if page = 1 then
response.write "<font color=darkgray>首页 前页</font>"
else
response.write "<a href=allnews.asp?class="&action&"&page=1>首页</a> <a href=allnews.asp?
class="&action&"&page="&page-1&">前页</a>"
end if
if page = allpages then
response.write "<font color=darkgray> 下页 末页</font>"
else
response.write " <a href=allnews.asp?class="&action&"&page="&page+1&">下页</a> <a
href=allnews.asp?class="&action&"&page="&allpages&">末页</a>"
end if
response.write " 第"&page&"页 共"&allpages&"页 </td></tr>"
end sub
rsf.close
set rsf=nothing
conn.close
set conn=nothing
%>
热心网友
时间:2024-11-26 11:21
你最后分页输出的时候没对;
你先算个条数totalPut=rs.recordcount
再自己定个每页最条数maxperpage;
就别用那个for每次来定义了。用下面这个分页输出吧。
<p
align="center"><%
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
"<br><div
align='center'>"
Response.Write
"<p
align='center'
class='mnu'>
"
If
CurrentPage<2
Then
Response.Write
"<font
class='mnu'>首页
上一页</font>
"
Else
Response.Write
"<a
href="&filename&"?page=1
class='mnu'>首页</a>
"
Response.Write
"<a
href="&filename&"?page="&CurrentPage-1&"
class='mnu'>上一页</a>
"
End
If
If
n-currentpage<1
Then
Response.Write
"<font
class='mnu'>下一页
尾页</font>"
Else
Response.Write
"<a
href="&filename&"?page="&(CurrentPage+1)&"
class='mnu'>"
Response.Write
"下一页</a>
<a
href="&filename&"?page="&n&"
class='mnu'>尾页</a>"
End
If
Response.Write
"<font
class='mnu'>
页次:</font><font
class='contents'>"&CurrentPage&"</font><font
class='mnu'>/"&n&"页</font>
"
Response.Write
"<font
class='mnu'>
共有"&totalnumber&"条记录
"&maxperpage&"条记录/页</font>
"
Response.Write
"<font
class='mnu'>转到:</font><input
type='text'
name='page'
size=2
maxlength=10
class=fr2
value="¤tpage&">"
Response.Write
" <input
type='submit'
class=fr2
value='GO'
name='cndok'></div></form>"
End
Function
end
if
%></p>
<p
align="center"> </p>
热心网友
时间:2024-11-26 11:22
循环体放置错误!
热心网友
时间:2024-11-26 11:23
把page=page-1去点