| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 584 人关注过本帖
标题:[求助]循环输出的问题
只看楼主 加入收藏
疯狂IT界
Rank: 1
等 级:新手上路
帖 子:83
专家分:0
注 册:2006-6-6
收藏
 问题点数:0 回复次数:7 
[求助]循环输出的问题

这种循环怎么写

1。每循环一次 i 的值都加 1
2。循环到数据库为空的时候就停止
3。每页显示10条记录

我是这么写的 ,可是不行

<%for i=1 to rs.pagesize or rs.eof%>

这么写 页面显示完最后一条后就出现这个了.........晕了,

ADODB.Field 错误 '80020009'

BOF 或 EOF 中有一个是“真”,或者当前的记录已被删除,所需的操作要求一个当前的记录。

/lx.asp,行 0

搜索更多相关主题的帖子: 输出 
2006-08-03 13:13
wyg4859
Rank: 2
等 级:新手上路
威 望:4
帖 子:883
专家分:0
注 册:2006-8-2
收藏
得分:0 
要不你就在后面加上if rs.eof then exit for end if看看行吗

http://www.找到组织!找到党!
2006-08-03 13:28
疯狂IT界
Rank: 1
等 级:新手上路
帖 子:83
专家分:0
注 册:2006-6-6
收藏
得分:0 
不行, 这样写的效果和我写的那个差不多, 都不行 哎,没有人能帮我解决下吗? 版主帮我好吗?
2006-08-03 15:25
做人很低调
Rank: 5Rank: 5
等 级:贵宾
威 望:18
帖 子:1268
专家分:0
注 册:2006-8-2
收藏
得分:0 
你说的和分页的代码很像  下边是我自己写的  还经常用的代码 你自己看
有要改的地方自己改吧  我注释的很细了 让你看下思路  


&lt;head&gt;
&lt;meta http-equiv="Content-Type" content="text/html; charset=gb2312" /&gt;
&lt;title&gt;无标题文档&lt;/title&gt;
&lt;%
'声明了drecord(单页显示的记录数)
const drecord = 5            
'判断page是否有值,如果有值,将page值赋给dpage(当前的页数)
if not isempty(request.QueryString("page")) then      
    dpage = cint(request.QueryString("page"))        
else
'如果dpage没有值,就给dpage初始化  值为1
    dpage = 1               
end if
%&gt;
&lt;/head&gt;

&lt;body&gt;
&lt;%
'创建记录集
set rs = server.CreateObject("adodb.recordset")
sql = "select * from newstable order by id desc "
rs.open sql,conn,1,1
'判断数据库中是否有记录
if rs.eof and rs.bof then
    response.Write "对不起,暂时没有新闻!"
else
'有记录,就将记录的总数赋给mrecord(记录的总数)
    mrecord = rs.recordcount
'判断一共要分多少页,将页数赋给mpage(总页数)
    if (mrecord mod drecord) = 0 then
        mpage = mrecord \ drecord
    else
        mpage = mrecord \ drecord + 1
    end if
'判断当前是否是第一页,若不是就将rs记录集下移   
    if dpage &lt;&gt; 1 then
        t = drecord * (dpage -1)
        rs.move t
    end if
'调用showcontent过程
        showcontent
        
        response.Write "&lt;p align = 'left'&gt;信息分页"
'进行for循环,循环输出分页号码   
        for k = 1 to mpage
        
            if k = dpage then
                response.Write "[&lt;b&gt;"&amp;cstr(k)&amp;"&lt;/b&gt;]"
            else
                response.Write "[&lt;b&gt;&lt;a href = 'index.asp?page="&amp;cstr(k)&amp;"'&gt;"&amp;cstr(k)&amp;"&lt;/a&gt;&lt;/b&gt;]"
            end if
            
        next
'显示出当前页是多少
        if isempty(request("page")) then
            response.Write "当前为第1页"
        else
            response.Write "当前为第"&amp;cstr(request("page"))&amp;"页"
        end if
'显示出上下翻页功能        
        if dpage = 1 then
            response.Write "&lt;b&gt;&lt;a href='index.asp?page="&amp;dpage+1&amp;"'&gt;下一页&lt;/a&gt;&lt;/b&gt;"
        elseif dpage = mpage then
            response.Write "&lt;b&gt;&lt;a href='index.asp?page="&amp;dpage-1&amp;"'&gt;上一页&lt;/a&gt;&lt;/b&gt;"
        else
            response.Write "&lt;b&gt;&lt;a href='index.asp?page="&amp;dpage+1&amp;"'&gt;下一页&lt;/a&gt;&lt;/b&gt;"
            response.Write "&lt;b&gt;&lt;a href='index.asp?page="&amp;dpage-1&amp;"'&gt;上一页&lt;/a&gt;&lt;/b&gt;"   
        end if
        
        response.Write "&lt;p&gt;"
            
end if
'showcontent存储过程
sub showcontent
    i = 0
%&gt;
&lt;table width="487" border="0"&gt;
  &lt;tr&gt;
    &lt;td width="151"&gt;&lt;div align="center"&gt;id&lt;/div&gt;&lt;/td&gt;
    &lt;td width="153"&gt;&lt;div align="center"&gt;title&lt;/div&gt;&lt;/td&gt;
    &lt;td width="169"&gt;&lt;div align="center"&gt;news&lt;/div&gt;&lt;/td&gt;
  &lt;/tr&gt;
  
  &lt;%do while not rs.eof%&gt;
  
  &lt;tr&gt;
    &lt;td&gt;&lt;div align="center"&gt;&lt;%=rs("id")%&gt;&lt;/div&gt;&lt;/td&gt;
    &lt;td&gt;&lt;div align="center"&gt;&lt;%=rs("title")%&gt;&lt;/div&gt;&lt;/td&gt;
    &lt;td&gt;&lt;div align="center"&gt;&lt;%=rs("news")%&gt;&lt;/div&gt;&lt;/td&gt;
  &lt;/tr&gt;
  
  &lt;%
'进行判断,确保每也输出的记录数为5条,大于5条立即停止do while循环
  i = i + 1
  if i &gt;= 5 then
      exit do
  end if
  rs.movenext
  loop
  %&gt;
  
&lt;/table&gt;

&lt;%
end sub
%&gt;

&lt;/body&gt;

其实我很低调,只是你不知道...
2006-08-03 15:56
hangxj
Rank: 6Rank: 6
等 级:贵宾
威 望:29
帖 子:2045
专家分:0
注 册:2006-4-10
收藏
得分:0 

发一个我很早以前的分页的代码吧,可以实现页码下拉跳转,具体实现要看个人的情况

<%
newsperpage=10 '设置每页显示数
set rs = server.CreateObject("Adodb.recordset")
SqlStr = "Select * from ......." 'SQL语句自己写

Rs.open SqlStr,conn,1,1
totalnews=rs.recordcount
if not rs.eof then
rs.movefirst
rs.pagesize=newsperpage
if SafeRequest("page",1)<>"" then 'SafeRequest为我的自定义函数,自己可以改在自己的,要是没有就改成Request
currentpage=clng(SafeRequest("page",1))
if currentpage>rs.pagecount then
currentpage=rs.pagecount
end if
else
currentpage=1
end if
if currentpage<>1 then
if (currentpage-1)*newsperpage<totalnews then
rs.move(currentpage-1)*newsperpage
bookmark=rs.bookmark
end if
end if
if (totalnews mod newsperpage)=0 then
totalpages=totalnews\newsperpage
else
totalpages=totalnews\newsperpage+1
end if
%>
<br>
</p>
<TABLE width="94%" border=0 align="center" cellPadding=2 cellSpacing=0 bgcolor="#f5f5f5">
<TBODY>
<TR>
<TD width="50%" class="C lh15">共有新品 <font color=#FF6600><b><%=totalnews%></b></font> 件<%=year(myyear)%> <%=month(mymonth)%></TD>
</TR>
</TBODY>
</TABLE>
<br>
<TABLE width="94%" border=0 align="center" cellPadding=2 cellSpacing=0 bgcolor="#f5f5f5">
<TBODY>
<TR><form method="post" action="?">
<TD height="30" align="center" class="C lh15"> 共&nbsp;<font color="#FF6666"><b><%=totalnews%></b></font>&nbsp;条&nbsp;当前&nbsp;<font color="#FF6666"><%=(CurrentPage-1)*newsperpage+1%></font>&nbsp;~
<font color="#FF6666"><%if CurrentPage*newsperpage>totalnews then response.write totalnews end if
if CurrentPage*newsperpage<=totalnews then response.write CurrentPage*newsperpage end if%></font>&nbsp;条
&nbsp;&nbsp;页次:<font color="#FF6666"><b><%=CurrentPage%></b></font>/<b><%=totalpages%></b>&nbsp;页&nbsp;&nbsp;<font color="#FF6666"><b><%=newsperpage%></b></font>&nbsp;条/页 <%
if CurrentPage<2 then
response.write "<font color='999966'>首页 上一页</font> "
else
response.write "<a href=?page=1>首页</a> "
response.write "<a href=?page="&currentpage-1&">上一页</a> "
end if
if totalpages-currentpage<1 then
response.write "<font color='999966'>下一页 尾页</font>"
else
response.write "<a href=?page="&currentpage+1&">下一页</a>"
response.write " <a href=?page="&totalpages&">尾页</a>"
end if
%> <select name="go" onChange='window.location=form.go.options[form.go.selectedIndex].value'>
<%
i=1
for i=1 to totalpages
if i=currentpage then
%>
<option value=<%=i%> selected>第<%=i%>页</option>
<%else%>
<option value='?page=<%=i%>'>第<%=i%>页</option>
<%end if
next%>
</select>
<input type="submit" name="Submit" value="转向"></TD></form>
</TR>
</TBODY>
</TABLE>
<TABLE width="94%" border=0 align="center" cellPadding=2 cellSpacing=0 bgcolor="#f5f5f5">
<TBODY>
<TR>
<TD width="15%" align="center" class="C lh15">产品缩略图</TD>
<TD width="15%" align="center" class="C lh15">产品名</TD>
<TD width="25%" align="center" class="C lh15">产品分类</TD>
<TD width="15%" align="center" class="C lh15">产品价格(元)</TD>
<TD width="10%" align="center" class="C lh15">现有库存</TD>
<TD width="20%" align="center" class="C lh15">操作</TD>
</TR>
</TBODY>
</TABLE>
<%i=0
do while not rs.eof and i<newsperpage
sql="select * from class_1 where sortid="&rs("sortid")&""
set rs2=conn.execute(sql)
sql="select * from class_2 where typeid="&rs("typeid")&""
set rs3=conn.execute(sql)
sql="select * from class_3 where class_id="&rs("classid")&""
set rs4=conn.execute(sql)%>
<TABLE width="94%" border=0 align="center" cellPadding=2 cellSpacing=1 <%if i mod 2 = 0 then%>bgcolor="#ffffff"<%else%>bgcolor="#f5f5f5"<%end if%>>
<TBODY>
<TR>
<TD width="15%" align="center" class="C lh15"><a href="?action=view&id=<%=rs("product_ID")%>"><img src="<%=rs("Product_Pic")%>" alt="点击查看详情" width=87 height=50 border=0></a></TD>
<TD width="15%" align="center" class="C lh15"><%=Rs("Product_Name")%></TD>
<TD width="25%" align="center" class="C lh15"><%=rs("Add_time")%></TD>
<TD width="15%" align="center" class="C lh15"><%=Rs("Product_Dj")%></TD>
<TD width="10%" align="center" class="C lh15"><%=Rs("kc")%></TD>
<TD width="20%" align="center" class="C lh15"><a href="?action=view&id=<%=rs("product_ID")%>"><font color=#FF6600>详情</font></a>&nbsp;&nbsp;<a href="javascript:;" onClick="javascript:window.open('shopcart.asp?product_id=<%=rs("product_ID")%>&user_id=<%=rs("User_ID")%>&action=add','shouchang','width=600,height=400,toolbar=no, status=no, menubar=no, resizable=yes, scrollbars=yes');"><font color=#FF6600>订购</font></a>&nbsp;&nbsp;<a href="?action=view_Scs&id=<%=rs("User_ID")%>"><font color=#FF6600>联系厂家</font></a></TD>
</TR>
</TBODY>
</TABLE>
<%
rs4.close
set rs4=nothing
rs3.close
set rs3=nothing
rs2.close
set rs2=nothing
i=i+1
rs.movenext
loop
%>
<TABLE width="94%" border=0 align="center" cellPadding=2 cellSpacing=0 bgcolor="#f5f5f5">
<TBODY>
<TR><form method="post" action="?">
<TD height="30" align="center" class="C lh15"> 共&nbsp;<font color="#FF6666"><b><%=totalnews%></b></font>&nbsp;条&nbsp;当前&nbsp;<font color="#FF6666"><%=(CurrentPage-1)*newsperpage+1%></font>&nbsp;~
<font color="#FF6666"><%if CurrentPage*newsperpage>totalnews then response.write totalnews end if
if CurrentPage*newsperpage<=totalnews then response.write CurrentPage*newsperpage end if%></font>&nbsp;条&nbsp;&nbsp;页次:<font color="#FF6666"><b><%=CurrentPage%></b></font>/<b><%=totalpages%></b>&nbsp;页&nbsp;&nbsp;<font color="#FF6666"><b><%=newsperpage%></b></font>&nbsp;条/页 &nbsp;
<%
if CurrentPage<2 then
response.write "<font color='999966'>首页 上一页</font> "
else
response.write "<a href=?page=1>首页</a> "
response.write "<a href=?page="&currentpage-1&">上一页</a> "
end if
if totalpages-currentpage<1 then
response.write "<font color='999966'>下一页 尾页</font>"
else
response.write "<a href=?page="&currentpage+1&">下一页</a>"
response.write " <a href=?page="&totalpages&">尾页</a>"
end if
%> <select name="page">
<%
i=1
for i=1 to totalpages
if i=currentpage then
%>
<option value=<%=i%> selected>第<%=i%>页</option>
<%else%>
<option value=<%=i%>>第<%=i%>页</option>
<%end if
next%>
</select>
<input type="submit" name="Submit" value="转向"> </TD></form>
</TR>
</TBODY>
</TABLE>
<%else
if rs.eof and rs.bof then
%>
<TABLE width="94%" border=0 align="center" cellPadding=2 cellSpacing=0 bgcolor="#f5f5f5">
<TBODY>
<TR>
<TD align="center" class="C lh15">当前没有产品</TD>
</TR>
</TBODY>
</TABLE>
<%end if
end if
%>


http://www./
2006-08-03 16:06
做人很低调
Rank: 5Rank: 5
等 级:贵宾
威 望:18
帖 子:1268
专家分:0
注 册:2006-8-2
收藏
得分:0 
汗。。比我的长  不过意思都一样  程序这玩意一通百通

其实我很低调,只是你不知道...
2006-08-03 16:09
疯狂IT界
Rank: 1
等 级:新手上路
帖 子:83
专家分:0
注 册:2006-6-6
收藏
得分:0 
我已经解决
2006-08-03 17:57
pucb
Rank: 2
等 级:论坛游民
帖 子:290
专家分:10
注 册:2006-8-1
收藏
得分:0 
呵呵

没有个性,哪来签名!
2006-08-05 12:25
快速回复:[求助]循环输出的问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.020257 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved