应用实例可以参照:西南本本网——笔记本渠道专家(http://www.xnbenben.com)
上一条记录的ID:(小于的最大值)
select max(id) from ... where id<yourid
下一条记录的ID
select min(id) from .... where Id>yourid
并在一起
select ..,(select max(id) from ... where id<yourid) as ..,(select min(id) from .... where Id>yourid) as .. from ....
当前文章显示界面只记录当前文章的ID即可.
比如当前显示文章ID为:5
在点击下一页时.传URL.
Response.Redirect("http://www.xnbenben.com/News_List_Xi.aspx?ID="+(ID+1).ToString());
ID+1后的值是否上溢或下溢,在ReadArticle页面初始化时判断即可
CREATE PROCEDURE pTable2_getPN
@titleid varchar(30)
AS
declare @kind varchar(30),@P varchar(100),@Pid varchar(30),@Ptitle varchar(50),@N varchar(100),@Nid varchar(30),@Ntitle varchar(50)
set @kind=(select top 1 kind from table2 where id=@titleid)
select top 1 @Ptitle=title,@Pid=id from table2 where id<convert(int,@titleid) and kind=@kind order by id desc
select top 1 @Ntitle=title,@Nid=id from table2 where id>convert(int,@titleid) and kind=@kind order by id
if @Ptitle is null
set @Ptitle=''
if @Pid is null
set @Pid=''
if @Ntitle is null
set @Ntitle=''
if @Nid is null
set @Nid=''
set @P='<Li>上一篇 :<A href="http://www.xnbenben.com/News_List_Xi.aspx?id='+@Pid+'">'+@Ptitle+'</A>'
set @N='<Li>下一篇 :<A href="http://www.xnbenben.com/News_List_Xi.aspx?id='+@Nid+'">'+@Ntitle+'</A>'
select @P+'<br>'+@N as innerhtml
GO
select top 1 Id from table1 where id>yourid order by id asc
select top1 id from table1 where id<yourid order by id desc
自查询 select * from NewsTable a inner join (select max(id) as id2 from NewsTable where id<515) as b on a.id=b.id2