这种循环怎么写
1。每循环一次 i 的值都加 1
2。循环到数据库为空的时候就停止
3。每页显示10条记录
我是这么写的 ,可是不行
<%for i=1 to rs.pagesize or rs.eof%>
这么写 页面显示完最后一条后就出现这个了.........晕了,
ADODB.Field 错误 '80020009'
BOF 或 EOF 中有一个是“真”,或者当前的记录已被删除,所需的操作要求一个当前的记录。
/lx.asp,行 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"> 共 <font color="#FF6666"><b><%=totalnews%></b></font> 条 当前 <font color="#FF6666"><%=(CurrentPage-1)*newsperpage+1%></font> ~
<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> 条
页次:<font color="#FF6666"><b><%=CurrentPage%></b></font>/<b><%=totalpages%></b> 页 <font color="#FF6666"><b><%=newsperpage%></b></font> 条/页 <%
if CurrentPage<2 then
response.write "<font color='999966'>首页 上一页</font> "
else
response.write "<a href=?page=1>首页</a> "
response.write "<a href=?page="¤tpage-1&">上一页</a> "
end if
if totalpages-currentpage<1 then
response.write "<font color='999966'>下一页 尾页</font>"
else
response.write "<a href=?page="¤tpage+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> <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> <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"> 共 <font color="#FF6666"><b><%=totalnews%></b></font> 条 当前 <font color="#FF6666"><%=(CurrentPage-1)*newsperpage+1%></font> ~
<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> 条 页次:<font color="#FF6666"><b><%=CurrentPage%></b></font>/<b><%=totalpages%></b> 页 <font color="#FF6666"><b><%=newsperpage%></b></font> 条/页
<%
if CurrentPage<2 then
response.write "<font color='999966'>首页 上一页</font> "
else
response.write "<a href=?page=1>首页</a> "
response.write "<a href=?page="¤tpage-1&">上一页</a> "
end if
if totalpages-currentpage<1 then
response.write "<font color='999966'>下一页 尾页</font>"
else
response.write "<a href=?page="¤tpage+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
%>