查看: 1123|回复: 2

[ASP入门] 请问各位大神,asp中的sql如何查询第2-3条记录?

[复制链接]
糊涂 发表于 2023-3-1 12:07:55 | 显示全部楼层 |阅读模式
原来的代码:

<%         
set rs = server.createobject("adodb.recordset")
sql="select top 3 id,ClassId,TopID,InfoName,BigPic,Content,addtime from io where  ViewFlag=1 order by VoticeFlag desc,id desc"
rs.open sql,conn,1,1
if rs.bof and rs.eof then
response.write "<h2>无信息</h2>"
else
//第一部分
response.write "<h2><a  href='Show.asp?InfoId="&rs("ID")&"&ClassId="&rs("ClassId")&"&Topid="&rs("TopID")&"' target='_blank'>"&rs("InfoName")&"</a></h2>"
response.write "<div class='hot-news-list'> "
for i=2 to 3
if rs.eof then exit for
//第二部分
response.write "【<a href='Show.asp?InfoId="&rs("ID")&"&ClassId="&rs("ClassId")&"&Topid="&rs("TopID")&"' target='_blank'>"&rs("InfoName")&"</a>】 &nbsp;"
rs.movenext
next
response.write "</div> "
end if
rs.close
%>

上述源码在显示上有一个缺陷
第一部分显示了第一条数据
第二部分显示的是第1-2条数据(没有按设计显示第2-3条数据)
请教各位大神,这个该怎么修改。

另外,我有一个不成熟的想法,就是拆分处理

<%         
//第一部分
set rs = server.createobject("adodb.recordset")
sql="select top 1 id,ClassId,TopID,InfoName,BigPic,Content,addtime from io where  ViewFlag=1 order by VoticeFlag desc,id desc"
rs.open sql,conn,1,1
if rs.bof and rs.eof then
response.write "<h2>无信息</h2>"
else
response.write "<h2><a  href='Show.asp?InfoId="&rs("ID")&"&ClassId="&rs("ClassId")&"&Topid="&rs("TopID")&"' target='_self'>"&rs("InfoName")&"</a></h2>"
end if
rs.close
//第二部分
set rs = server.createobject("adodb.recordset")
//该这个sql语句为显示第2-3条记录
sql="select top 3 id,ClassId,TopID,InfoName,BigPic,Content,addtime from io where  ViewFlag=1 order by VoticeFlag desc,id desc"
rs.open sql,conn,1,1
if rs.bof and rs.eof then
else
response.write "<div class='hot-news-list'> "
for i=2 to 3
if rs.eof then exit for
response.write "【<a href='Show.asp?InfoId="&rs("ID")&"&ClassId="&rs("ClassId")&"&Topid="&rs("TopID")&"' target='_self'>"&rs("InfoName")&"</a>】 &nbsp;"
rs.movenext
next
response.write "</div> "
end if
rs.close
%>
很显然,技术有限,不懂怎么改这个“sql语句为显示第2-3条记录”,求各位大神指导。
海阔天空 发表于 2023-3-1 16:47:00 | 显示全部楼层
不用这么麻烦,打开RS后,先来个rs.movenext不就行了?
xuanxiao 发表于 2023-3-1 17:27:07 | 显示全部楼层

  1. rs.MoveFirst
  2. rs.Move 2
复制代码


查询第二条记录
您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表

在线客服

售前咨询
售后咨询
服务热线
023-58418553
微信公众号