虚无世界1合成表大全:谁晓得这段代码有什么问题?

来源:百度文库 编辑:杭州交通信息网 时间:2024/05/10 09:28:48
<%
set rs=server.createobject("adodb.recordset")
sql="select id,Newtitle,treename,treeid from News where treename='<公司动态' ORDER BY id desc"
rs.open sql,conn,1,3
count=0
if rs.Bof then
response.write "<FONT COLOR='#FF0000'><div align='center'>还没有新闻内容!</div></FONT>"
else
do while not rs.eof and count<3
Newtitle=rs("Newtitle")
if len(Newtitle)>21 then Newtitle=left(Newtitle,21)&"..."
%>
这段代码 显示方面问题 没控制好显示范围。
不是 是BOF 我早试过了 而且在这里并没有必要记数
你们看我有没有必要改一下我的限制语句 改为限制ID号比较容易判断而且运行速度也能好一些.

这里面程序有问题.我帮你改一下:
<%
set rs=server.createobject("adodb.recordset")
sql="select id,Newtitle,treename,treeid from News where treename='<公司动态' ORDER BY id desc"
rs.open sql,conn,1,3
count=0
if rs.eof then '应该是eof,而不是bof
response.write "<FONT COLOR='#FF0000'><div align='center'>还没有新闻内容!</div></FONT>"
else
do while not rs.eof and count<3
count=count+1 '要进行计数
Newtitle=rs("Newtitle")
if len(Newtitle)>21 then Newtitle=left(Newtitle,21)&"..."
%>

<!--循环内容-->

<%rs.movenext
loop%>

回答补充:
我明白了 你的计数器和循环以及指针都放在显示的后边了,那这部分是没有问题了。

sql语句似乎有点问题:treename='<公司动态'

怎么前边有“<”??
看看是不是这个原因

--------------
这段代码错误很多啊!

首先你的count计数器没有累加

前边 count=0

下面有个循环 do while not rs.eof and count<3

而没看到有累加

按你现在的做法,显示出来的应该是全部的公司动态,而没有按你想做的那样只显示3条。

另外 if rs.Bof then 建议修改为:
if rs.bof and rs.eof then

还有:do while 后边应该有 loop
并且数据指针需要移动
rs.movenext
loop