用asp写一个分页函数,每页显示10条记录,具有首页,上一页,下一页,尾页,当前页/总页数等功能,谢谢了
展开全部
%
const MaxPerPage=10
'分页显示新闻个数
dim totalput,currentPage,TotalPages,typ,sql
typ=request.QueryString("type")
if typ<>"" then
if not isempty(request.querystring("num")) then
currentPage=cint(request.querystring("num"))
else
currentPage=1
end if
%>
<%
sql="select * from news where news_type="&typ&" order by news_time desc"
rs.open sql,conn,1,1
totalPut=rs.recordcount
if rs.eof then
response.write "<p align='center'> 没有相关新闻</p>"
else
if currentpage<1 then
currentpage=1
end if
if (currentPage-1)*MaxPerPage<totalPut then
rs.move (currentPage-1)*MaxPerPage
showContent
showpages
end if
end if
if (currentPage-1)*MaxPerPage=totalPut then
rs.move (currentPage-1)*MaxPerPage
showContent
showpages
end if
%>
<%
sub showContent()
i=0
response.write "<div align=center><table width=100% border=0 cellspacing=0 cellpadding=0 > "
do while not rs.eof
response.write "<tr class=9p><td width=9% height=25 align=center valign=middle class=9red>★</td>"
dim url
if rs("news_jg")="1" then
url="news_detail1.asp?id=" & rs("id")
else
url="news_detail2.asp?id=" & rs("id")
end if
response.write " <td width=91% height=25 align=left valign=middle class=hand onClick=MM_openBrWindow('"&url&"','新闻','scrollbars=yes,resizable=yes,width=556,height=360')> "
if len(rs("news_title"))>20 then
response.write left(rs("news_title"),18)&".."&"<"&year(rs("news_time"))&"/"&month(rs("news_time"))&">"
else
response.write rs("news_title")&"<"&year(rs("news_time"))&"/"&month(rs("news_time"))&">"
end if
response.write "</td></tr>"
i=i+1
if i>=MaxPerPage then
exit do
else
rs.movenext
end if
loop
response.write"</td></tr></table></div>"
end sub %>
<%
sub showpages()
dim n
if (totalPut mod MaxPerPage)=0 then
n= totalPut \ MaxPerPage
else
n= totalPut \ MaxPerPage + 1
end if
if n=0 then
response.write "<p align='right'>本类没有新闻</p>"
exit sub
end if
dim k
response.write "<div align=center><br>分页 >> "
if currentPage<>n then
for k=1 to n
if k=currentPage then
response.write"["+Cstr(k)+"]"
else
response.write"<a href=show_newsmore.asp?num="&cstr(k)&"&type='"&trim(rs("news_type"))&"'>[" &Cstr(k)&" ]</a>"
end if
next
response.write "</div> "
else
response.write "最后一页"&"<a href='#'onclick=javascript:history.go(-1)> 返回</a> "
end if
end sub
%>
<%
rs.close
set rs=nothing
conn.close
set conn=nothing %>
const MaxPerPage=10
'分页显示新闻个数
dim totalput,currentPage,TotalPages,typ,sql
typ=request.QueryString("type")
if typ<>"" then
if not isempty(request.querystring("num")) then
currentPage=cint(request.querystring("num"))
else
currentPage=1
end if
%>
<%
sql="select * from news where news_type="&typ&" order by news_time desc"
rs.open sql,conn,1,1
totalPut=rs.recordcount
if rs.eof then
response.write "<p align='center'> 没有相关新闻</p>"
else
if currentpage<1 then
currentpage=1
end if
if (currentPage-1)*MaxPerPage<totalPut then
rs.move (currentPage-1)*MaxPerPage
showContent
showpages
end if
end if
if (currentPage-1)*MaxPerPage=totalPut then
rs.move (currentPage-1)*MaxPerPage
showContent
showpages
end if
%>
<%
sub showContent()
i=0
response.write "<div align=center><table width=100% border=0 cellspacing=0 cellpadding=0 > "
do while not rs.eof
response.write "<tr class=9p><td width=9% height=25 align=center valign=middle class=9red>★</td>"
dim url
if rs("news_jg")="1" then
url="news_detail1.asp?id=" & rs("id")
else
url="news_detail2.asp?id=" & rs("id")
end if
response.write " <td width=91% height=25 align=left valign=middle class=hand onClick=MM_openBrWindow('"&url&"','新闻','scrollbars=yes,resizable=yes,width=556,height=360')> "
if len(rs("news_title"))>20 then
response.write left(rs("news_title"),18)&".."&"<"&year(rs("news_time"))&"/"&month(rs("news_time"))&">"
else
response.write rs("news_title")&"<"&year(rs("news_time"))&"/"&month(rs("news_time"))&">"
end if
response.write "</td></tr>"
i=i+1
if i>=MaxPerPage then
exit do
else
rs.movenext
end if
loop
response.write"</td></tr></table></div>"
end sub %>
<%
sub showpages()
dim n
if (totalPut mod MaxPerPage)=0 then
n= totalPut \ MaxPerPage
else
n= totalPut \ MaxPerPage + 1
end if
if n=0 then
response.write "<p align='right'>本类没有新闻</p>"
exit sub
end if
dim k
response.write "<div align=center><br>分页 >> "
if currentPage<>n then
for k=1 to n
if k=currentPage then
response.write"["+Cstr(k)+"]"
else
response.write"<a href=show_newsmore.asp?num="&cstr(k)&"&type='"&trim(rs("news_type"))&"'>[" &Cstr(k)&" ]</a>"
end if
next
response.write "</div> "
else
response.write "最后一页"&"<a href='#'onclick=javascript:history.go(-1)> 返回</a> "
end if
end sub
%>
<%
rs.close
set rs=nothing
conn.close
set conn=nothing %>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询