50求一实现思路

net205 2005-03-31 10:17:33
数据库里有一些文章记录,如:
id title content
--------------------------------------------
1 标题 内容
3 123 321
4 abc abc
.............................

我在List.asp页里以分页的形式把这些记录列出来,然后点连接read.asp?id=3转到文章的查看页里,
在这个查看页里面,我先根据这个id找到这篇文章,把它显示出来,我又想在这个页面下面加上这样的功能:<a href="read.asp?id=1">上一篇</a>|<a href="List.asp">目录</a>|<a href="read.asp?id=4">下一篇</a>,请问这个功能怎么做?我如何根据当前页的id来定位它的上一篇和下一篇文章的id


帮我讲讲思路。?????先谢过
...全文
142 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
lstup 2005-04-01
  • 打赏
  • 举报
回复
下一篇
sql = "select min(id) from [table] where id > "& id
上一篇
sql = "select max(id) from [table] where id < "& id

大概是这个意思
net205 2005-04-01
  • 打赏
  • 举报
回复
好。结帐
myvicy 2005-03-31
  • 打赏
  • 举报
回复
不连续的换就
sql="select top 1 id as p_id from table where id<"&id
sql="select top 1 id as n_id from table where id>"&id
holoon 2005-03-31
  • 打赏
  • 举报
回复
response.write"<a href='read.asp?id="&gid&"'>上一篇</a>|"

老是错,不好意思,呵呵。。
fyxw 2005-03-31
  • 打赏
  • 举报
回复
对,用比较大小的做法,前一篇就order by id desc,后一篇就order by id asc,就取top 1 就可以了
holoon 2005-03-31
  • 打赏
  • 举报
回复
dim rsg,gid
set rsg=server.createobject("adodb.recordset")
rsg.open"select top 1 [table] where id<"&id,conn,1,1
gid=rsg("id")
rsg.close
set rsg=nothing
response.write"<a href='read.asp?id=<%=gid%>'>上一篇</a>|"

下一篇同理。
holoon 2005-03-31
  • 打赏
  • 举报
回复
dim rsg,gid
rsg.open"select top 1 [table] where id<id",conn,1,1
gid=rsg("id")
rsg.close
set rsg=nothing
response.write"<a href='read.asp?id=<%=gid%>'>上一篇</a>|"

下一篇同理。
TSD 2005-03-31
  • 打赏
  • 举报
回复
+ -的方法在数据记录全是连续的情况可正常执行,但如果删除了某些记录就会有问题了。
net205 2005-03-31
  • 打赏
  • 举报
回复
TSD(因为你有而精彩) 的应该可行。。
where <" & id & " order by id 来定位。。试试。。。。
TSD 2005-03-31
  • 打赏
  • 举报
回复
把 GoFlag 改为:MyFlag
net205 2005-03-31
  • 打赏
  • 举报
回复
是不是我还没讲清楚呢??、
我那要实现的功能是在具体的文章页面read.asp里
你那个p_id=id-1,这个好像不行吧。数据库里的记录id不一定是连续的,可能能删掉一些
TSD 2005-03-31
  • 打赏
  • 举报
回复
<%
连接数据库代码省略

dim id,MyFlag,GoSql,GoRs

id=TRIM(request.QueryString("id"))
MyFlag=TRIM(request.QueryString("MyFlag"))

if isnumeric(id)=false or isnull(id)=true or id="" then
response.write "参数错误"
response.end
else
if GoFlag="0" then
GoSql="select id from table where <" & id & " order by id desc;"
elseif GoFlag="1" then
GoSql="select id from table where id>" & id & " order by id desc;"
end if

set goRs=Conn.execute(GoSql)
if goRs.bof and goRs.eof then
response.write "没有这个ID"
response.end
else
response.redirect("read.asp?id=" & goRs(0))
end if
set goRs=nothing
set conn=nothing
end if
%>

将上面保存为一个文件,如:GoPage.asp


假设当前页的ID变量为id,调用方法:

<a href="GoPage.asp?id=<%=id%>&Myflag=0">上一篇</a>

<a href="GoPage.asp?id=<%=id%>&Myflag=1">下一篇</a>
myvicy 2005-03-31
  • 打赏
  • 举报
回复
list.asp
---------------------------------------------------
<%
rs.open "select count(*) as id_count from table",conn
id=request("id")
if isnull(id) or len(id)=0 then id=1
p_id=id-1
n_id=id+1
p_str=""
n_str=""
if p_id>0 then p_str="<a href='read.asp?id=<%=p_id%>'>上一篇</a>|"
if n_id<id_count then n_str="|<a href='read.asp?id=<%=n_id%>'>下一篇</a>"
write_str=p_str+"<a href='List.asp'>目录</a>|"+n_str
%>
<%=write_str%>

28,406

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧