菜鸟问题---100分,可用马上结帐。

bigfoxer 2003-12-01 03:20:28
<%
Response.Expires = 0
usr=Request("usr")
fenlei=Request("fenlei")

set conn=server.createobject("adodb.connection")
DBPath=("/html/data/manage.mdb")
conn.Open "driver={Microsoft Access Driver (*.mdb)};dbq="&DBPath
set rs=server.createobject("adodb.recordset")
sql="select company,ndir,nurl,pagenum from html where usr='"&usr&"'"
rs.open sql,conn,1,1

If rs.eof Then
%>
<SCRIPT Language="VBScript">
MsgBox "参数错误!"
Location.href="Javascript:history.back()"
</SCRIPT>
<%
rs.close
set rs=nothing
conn.close
set conn=nothing
Response.End
End If

nurl = rs("nurl")
rs.close
conn.close
%>

<%
DBPath=("/html/data/"&usr&"/html.mdb")
conn.Open "driver={Microsoft Access Driver (*.mdb)};dbq="&DBPath
if fenlei <> "" then
sql="select top 15 id,title,redirect,addtime,months,days from news where fenleiid = '"&fenlei&"' order by addtime desc,months desc,days desc"
else
sql="select top 15 id,title,redirect,addtime,months,days from news where commend = 1 order by addtime desc,days desc"
end if
rs.open sql,conn,1,1
list=""

if rs.eof then
list="<div align=center>暂时没有此类信息.</div>"
end if

do while not rs.eof
if rs("redirect")="" or rs("redirect")=null then
list=list&"<li>"&" "&"<a href="&nurl&"/"&rs("addtime")&"/"&rs("id")&".htm>"
else
list=list&"<li>"&" "&"<a href="&rs("redirect")&">"
end if
list=list&left(rs("title"),26)&"</a>"
list=list&"("&rs("months")&"-"&rs("days")&")<br>"
rs.movenext
loop

response.Write "document.write("""&list&""");"

rs.close
set rs = nothing
conn.close
set conn = nothing
response.end
%>

上面的我页面的调用程序。叫news.asp
问题是我控制的是显示15条新闻,但是显示的是17条,当加载几条新闻后就变成15条,再加变成16,再加-》17,好象要到18条时,再加就又变成15了,如此循环。请各位讲讲怎样固定到15条。
...全文
38 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
yeno 2003-12-01
  • 打赏
  • 举报
回复
sql="select top 15 id,title,redirect,addtime,months,days from news where commend = 1 order by addtime desc,days desc"
呵呵,楼主跟我犯的是同一类错误,因为你是搜索数据表中的前十五条记录,但是你所要查询的记录有可能在数据表记录的15条之后,所以出现了如示问题,解决方法如下:
if rs.eof then
list="<div align=center>暂时没有此类信息.</div>"
end if
i=1 '定义初始值
mycount=15 '定义你要显示记录的条数
do while not rs.eof
if rs("redirect")="" or rs("redirect")=null then
list=list&"<li>"&" "&"<a href="&nurl&"/"&rs("addtime")&"/"&rs("id")&".htm>"
else
list=list&"<li>"&" "&"<a href="&rs("redirect")&">"
end if
list=list&left(rs("title"),26)&"</a>"
list=list&"("&rs("months")&"-"&rs("days")&")<br>"
rs.movenext
i=i+1
if i>mycount then
exit do
loop


paz 2003-12-01
  • 打赏
  • 举报
回复
错了,上面那个是显示所有记录的,这个是显示15条记录
<%
Dim Repeat1__numRows
Dim Repeat1__index

Repeat1__numRows = 15
Repeat1__index = 0
Recordset1_numRows = Recordset1_numRows + Repeat1__numRows
%>
<%
While ((Repeat1__numRows <> 0) AND (NOT Recordset1.EOF))
%>
<tr bgcolor="#D2E0E1">
<td width="32" height="25" align="center" valign="middle" bgcolor="#2192CE"><img src="img/a1.gif" width="7" height="7"></td>
<td width="221" valign="top"><table width="100%" border="0" cellpadding="0" cellspacing="0">
<!--DWLayoutTable-->
<tr>
<td width="223" height="25" bgcolor="#3399CC" class="main"><A HREF="company.asp?<%= MM_keepURL & MM_joinChar(MM_keepURL) & "id=" & Recordset1.Fields.Item("id").Value %>" class="a02"><%=(Recordset1.Fields.Item("单位名称").Value)%></A></td>
</tr>
</table></td>
</tr>
<%
Repeat1__index=Repeat1__index+1
Repeat1__numRows=Repeat1__numRows-1
Recordset1.MoveNext()
Wend
%>
paz 2003-12-01
  • 打赏
  • 举报
回复
建议楼主用DW里记录集的重复区域这个服务器行为,比较省力。
<%
While ((Repeat1__numRows <> 0) AND (NOT Recordset1.EOF))
%>
<tr bgcolor="#D2E0E1">
<td width="32" height="25" align="center" valign="middle" bgcolor="#2192CE"><img src="img/a1.gif" width="7" height="7"></td>
<td width="221" valign="top"><table width="100%" border="0" cellpadding="0" cellspacing="0">
<!--DWLayoutTable-->
<tr>
<td width="223" height="25" bgcolor="#3399CC" class="main"><A HREF="company.asp?<%= MM_keepURL & MM_joinChar(MM_keepURL) & "id=" & Recordset1.Fields.Item("id").Value %>" class="a02"><%=(Recordset1.Fields.Item("单位名称").Value)%></A></td>
</tr>
</table></td>
</tr>
<%
Repeat1__index=Repeat1__index+1
Repeat1__numRows=Repeat1__numRows-1
Recordset1.MoveNext()
Wend
%>
bzscs 2003-12-01
  • 打赏
  • 举报
回复
i=0
do while not rs.eof
i=i+1:if i>15 then exit do
....
loop
bigfoxer 2003-12-01
  • 打赏
  • 举报
回复
可以讲讲我是那里有问题吗?
cuipi2003 2003-12-01
  • 打赏
  • 举报
回复
给你一个我朋友写的自动生成代码的工具,
www.hlinfo.com.cn/download/asptool.exe

28,407

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧