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

显示上一篇和下一篇标题的代码,怎么实现不了??

angerzl 发布于 2007-12-20 11:25, 1604 次点击
<%
pid1=rs("id")
function Getpre
sql="select top 1 * from news where id>"&pid1&" order by id"
set rs=conn.execute(sql)
if rs.eof or rs.bof then
response.Write("没有新闻了")
else
pid2=rs("id")
response.Write("<a href='shownews.asp?id="&pid2&"'>"&rs("title")&"</a>")
end if
end function

function Getnext
sql="select top 1 * from news where id<"&pid1&" order by id desc"
set rs=conn.execute(sql)
if rs.eof then
response.Write("没有新闻了")
else
pid3=rs("id")
response.Write("<a href='shownews.asp?id="&pid3&"'>"&rs("title")&"</a>")
end if
end function
%>
5 回复
#2
永夜的极光2007-12-20 11:33
错误提示 or 错误现象??
#3
angerzl2007-12-20 11:35
没有显示,没有错误提示
没有显示,没有错误提示
#4
威龙嘉少2007-12-20 22:03
要这个做什么啊?"order by id"
就一条记录还排什么序啊,去掉试下!
#5
angerzl2007-12-21 08:30
问题解决了,下面是最简单的实现代码
<%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%>

[[italic] 本帖最后由 angerzl 于 2007-12-21 09:47 编辑 [/italic]]
#6
kira0072007-12-21 10:31
本人觉得楼上的代码有个缺陷,该代码只能适用于连续的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" />
1