|  | 主题:  超难问题 | 
            
                        
                
                    |  NewSZQ
 职务:普通成员
 等级:1
 金币:0.0
 发贴:54
 
 | 
                            
                            #12002/4/7 23:26:16 
                                有1数据库,有一字段id(自动编号),能不能取出其中一个的同时取出相邻的两个如:
 id name sex
 1   aaa    b
 3   bbb    g
 4   ccc    g
 5   ddd    b
 8   eee    b
 取1的话同时取出3
 取3的话同时取出1、4
 取4的话同时取出3、5
 取8的话同时取出5
 id是随机的
 怎么办?
 谢谢
 | 
                        
                
                    |  有饭
 职务:普通成员
 等级:2
 金币:10.0
 发贴:669
 
 | 
                            
                            #22002/4/8 9:05:16 
                                我也想过这个问题,但是还是没有想到好的解决方法,我想用于自动显示下一篇的链接,和文章标题!
                             | 
                        
                
                    |  绿茶
 职务:普通成员
 等级:8
 金币:10.0
 发贴:19267
 
 | 
                            
                            #32002/4/8 12:25:04 
                                试试这样行不行id=request("id)
 sql="select * from table order by id"
 set rs=conn.execute(sql)
 if not rs.eof then
 idfirst=rs("id")
 rs.movelast
 idend=rs("id")
 if idfirst    idd1=id+1
 idd2=id-1
 sql1="select * from table where id="&idd1
 sql2="select * from table where id="&idd2
 end if
 
 if id=idfirst then
 idd1=id+1
 sql1="select * from table where id="&idd1
 end if
 if id=idend then
 idd1=id-1
 sql1="select * from table where id='"&idd1
 end if
 
 if id=idfirst=idend then
 sql1="select * from table where id="id"
 end if
 
 if sql1<>"" then
 set rs1=conn.execute(sql1)
 end if
 if sql2<>""  then
 set rs1=conn.execute(sql1)
 set rs2=conn.execute(sql2)
 end if
 .....
 end if
 
                                
                                    编辑历史:[这消息被germchen编辑过(编辑时间2002-04-08 12:47:55)]
 
 | 
                        
                
                    |  realice
 职务:普通成员
 等级:1
 金币:0.0
 发贴:9
 
 | 
                            
                            #42002/4/8 12:27:32 
                                用rs.MoveNext 可以吧,可以参考rs的语法
                             | 
                        
                
                    |  5D荣誉斑竹
 职务:普通成员
 等级:3
 金币:10.0
 发贴:1480
 
 | 
                            
                            #52002/4/8 12:40:16 
                                germchen在上个帖子中说 引用:
 试试这样行不行
 id=request("id)
 sql="select * from table order by id"
 set rs=conn.execute(sql)
 if not rs.eof then
 idfirst=rs("id")
 rs.movelast
 idend=rs("id")
 if idfirst    idd1=id+1
 idd2=id-1
 sql1="select * from table where id="&idd1
 sql2="select * from table where id="&idd2
 end if
 
 if id=idfirst then
 idd1=id+1
 sql1="select * from table where id="&idd1
 end if
 if id=idend then
 idd1=id-1
 sql1="select * from table where id='"&idd1
 end if
 
 if sql1<>"" then
 set rs1=conn.execute(sql1)
 end if
 if sql2<>""  then
 set rs1=conn.execute(sql1)
 set rs2=conn.execute(sql2)
 end if
 .....
 end if
 
 很严谨了。 我在BLUEIDEA也看到这篇帖子,那里帖了代码,基本也是这个做法, 但是他要问有没有快点的。 我写3条SQL: sql1="select * from table where id = "& id sql2="select top 1 * from table where id < "& id &" order by id DESC" sql3="select top 1 * from table where id > "& id 可行?
                             | 
                        
                
                    |  绿茶
 职务:普通成员
 等级:8
 金币:10.0
 发贴:19267
 
 | 
                            
                            #62002/4/8 12:49:46 
                                好像也可行吧
                             | 
                        
                
                    |  NewSZQ
 职务:普通成员
 等级:1
 金币:0.0
 发贴:54
 
 | 
                            
                            #72002/4/8 19:33:18 
                                看样子就只好先这样了,多谢各位
                             |