药渣湿料粉碎机:关于ASP显示记录的问题

来源:百度文库 编辑:查人人中国名人网 时间:2024/04/29 06:47:42
<%do while not Recordset1.eof %>
<%=(Recordset1.Fields.Item"title").Value)%><BR>
<%Recordset1.movenext
loop
%>
以上是我现在的显示代码,如果我只想显示最新的5条记录,该怎么修改,请指教。谢谢。

改一下sql语句
sql="select top 5 * from 表名 order by id desc"

要是代表中有修改时间字段或顺序ID的话,可以利用降序排出前五个来。

<%do while not Recordset1.eof %>
<%=(Recordset1.Fields.Item"title").Value)%><BR>
<%Recordset1.movenext
loop
%>

2种方法
一是你的记录集Recordset1的sql语句就只写个只显示5条记录的语句
sql="select * top 5 from table"
二是你在while条件里面加个条件,做个计数器,
temp=0
<%do while not Recordset1.eof and temp<=5 %>
<%=(Recordset1.Fields.Item"title").Value)%><BR>
<%Recordset1.movenext
temp=temp+1
loop
很长时间没有接触ASP了,语法不知道对不对,但是思想肯定是对的
%>