注册 登录
编程论坛 ASP技术论坛

实现上一篇和下篇ASP代码

angerzl 发布于 2007-12-21 09:48, 1090 次点击
<%rs.close
set rs=server.createobject("adodb.recordset")
sql="select * from news where id="&request("id")-1
rs.open sql,conn,1,1
  if rs.eof and rs.bof then
%>
                    <span class="STYLE10">上篇文章:</span>已经没有了
                    <%else%>
                    <br>
                    <span class="STYLE10">上篇文章:</span><a href="shownews.asp?id=<%=rs("id")%>"><%=rs("title")%></a>
                    <%end if%>
                    <BR>
                    <% rs.close
set rs=server.createobject("adodb.recordset")
sql="select * from news where id="&request("id")+1
rs.open sql,conn,1,1
  if rs.eof and rs.bof then
 %>
                    <span class="STYLE10">下篇文章:</span>已经没有了
                    <%else%>
                    <span class="STYLE10">下篇文章:</span><a href="shownews.asp?id=<%=rs("id")%>"><%=rs("title")%></a>
                    <%end if%>
3 回复
#2
kira0072007-12-21 10:27
本人觉得楼主的代码有个缺陷,该代码只能适用于连续的ID,当ID不连续的时候会出现“无法浏览”
以下为我使用的方式
-----------------------------------------------------------------------------------------------------------------------------
<%'向下向上翻页功能模块
function thenext '下篇文章
newrs=server.CreateObject("adodb.recordset")
sql="select top 1 * from product where id>"&id&" and smallclassid="&rspp("smallclassid")&" order by id"
set newrs=conn.execute(sql)
if newrs.eof then
response.Write"<img src='images/DD5.jpg' alt='下一件商品' width='15' height='13' border='0'>"
else
a2=newrs("id")
response.Write ("<a href='products.asp?id="&a2&"&smallclassid="&rspp("smallclassid")&"'>")
response.Write  "<img src='images/DD5.jpg' alt='下一件商品:"&newrs("name")&"' width='15' height='13' border='0'>"
response.Write ("</a>")
end if
end function
'下一篇文章功能结束
'上一篇文章
function thehead
headrs=server.CreateObject("adodb.recordset")
sql="select top 1 * from product where id<"&id&" and smallclassid="&rspp("smallclassid")&" order by id desc"
set headrs=conn.execute(sql)
if headrs.eof then
response.Write"<img src='images/DD6.jpg' alt='上一件商品' width='15' height='13' border='0'>"
else
a0=headrs("id")
AA= headrs("name")
response.Write ("<a href='products.asp?id="&a0&"&smallclassid="&rspp("smallclassid")&"'>")
response.Write "<img src='images/DD6.jpg' alt='上一件商品:"&aa&" ' width='15' height='13' border='0'>"
response.write ("</a>")
end if
end function%>
在需要使用 上一篇或下一篇 时 直接调用<% thenext %>或<% thehead %> 即可
-----------------------------------------------------------------------------------------------------------------------------
" border="0" />
#3
chzh222007-12-21 19:02
'===============显示上下篇新闻===============
dim RelationArt
set RelationArt = conn.execute("select top 1 news_id,news_title from [news] where news_id<"&aid&" and passed=0 order by news_id desc")
IF RelationArt.eof and relationArt.bof Then
contextual= "上篇新闻:已经没有了  &nbsp; "   
else
contextual= "上篇新闻:<a href=""Show.asp?id=" & RelationArt(0) & """>" & relationArt(1) & "</a>  &nbsp; "   
end if   
Set RelationArt=Nothing
set RelationArt = conn.execute("select top 1 news_id,news_title from [news] where news_id>"&aid&" and passed=0 order by news_id")
IF RelationArt.eof and relationArt.bof Then
contextual=contextual& "下篇新闻:已经没有了"   
else
contextual=contextual& "下篇新闻:<a href=""Show.asp?id=" & RelationArt(0) & """>" & relationArt(1) & "</a>"  
end if  
Set RelationArt=Nothing
#4
neler2008-04-23 10:37
那我想把分类ID加进去一起判断该怎么写?
我的代码是这样:
IF RelationArt.eof and relationArt.bof then
Response.Write "<font color=red>·上个作品:</font>已经没有了<BR> "   
else
Response.Write "<font color=red>·上个作品:</font><a href=""showset.asp?soft_id=" & RelationArt(0) & """>" & relationArt(1) & "</a><BR>"   
end if
1