ASP数组循环的问题
<%aResults=application("data")Dimi,row,pagesize,epage,numb,pagecount,fenyenumb=UBound...
<%
aResults=application("data")
Dim i,row,pagesize,epage,numb,pagecount,fenye
numb=UBound(aResults,2)+1 '总记录行数
pagesize=18 '每页条数
If numb Mod pagesize = 0 Then '判断总页数
pagecount=Int(numb/pagesize)
Else
pagecount=Int(numb/pagesize)+1
End If
epage=request.querystring("page")
If epage="" Then epage=1
For i=(epage-1)*pagesize To epage*pagesize-1
If i>UBound(aResults,2) Or i<0 Then Exit for
%>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<%j=1%>
<tr>
<%do while not aResults.eof%>
<td align=middle valign=center>
<a href=kanbao.asp?id=<%=aResults(0,i)%> target="_blank"><img src="upload/<%=aResults(6,i)%>" alt="<%=aResults(1,i)%>" width="160" height="120" border="0" align="absmiddle"><br><%=aResults(1,i)%></a><br><br><br>
<%If j Mod 3 = 0 Then%>
</td>
<%
j = j + 1
aResults.movenext
end if
Loop
%>
</tr>
</table>
<%
Next
If numb>pagesize Then
fenye="<a href=2009bb2.asp?page=1>首页</a> "
fenye=fenye&"<a href=2009bb2.asp?page="&epage-1&" title="&epage-1&">前页</a> "
fenye=fenye&"<a href=2009bb2.asp?page="&epage+1&" title="&epage+1&">后页</a> "
fenye=fenye&"<a href=2009bb2.asp?page="&pagecount&">末页</a> "
fenye=fenye&"总页数"&pagecount&",当前页"&epage&",总记录为:"&numb
response.write fenye
End if
%>
现在我需要将这个结果分三列自动换行显示,我知道是do while not aResults.eof的问题,但是应该怎么写才正确?请高手指点!
问题不在循环的写法上,循环写的没错。是aResults.eof的问题,不知道怎么写。去除do while not aResults.eof,aResults.movenext ,loop就可以,只是没有分列。
另外一个页面,aResults=application("data")data的代码:
<!--#include file="conn.asp"-->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head>
<body>
<%
sql="select * from news where BigclassName='宝宝秀'and SmallClassName='2009年宝宝秀' and imagenum>0 and infotime>='2008-11-1' and infotime<'2009-11-1' order by id asc"
Set rs=conn.execute(sql)
If rs.eof And rs.bof Then
response.Write("没有查找到您要的记录")
response.End
Else
aResults=rs.getrows()'取出数据放入数组ROW中
application("data")=aResults
Set rs=nothing
conn.close '关闭数据库
End IF
%>
<iframe src="2009bb2.asp" width="1000" height="1300" border="0" frameborder="0" framespacing="0" marginheight="0" marginwidth="0" scrolling="yes"></iframe>
</body> 展开
aResults=application("data")
Dim i,row,pagesize,epage,numb,pagecount,fenye
numb=UBound(aResults,2)+1 '总记录行数
pagesize=18 '每页条数
If numb Mod pagesize = 0 Then '判断总页数
pagecount=Int(numb/pagesize)
Else
pagecount=Int(numb/pagesize)+1
End If
epage=request.querystring("page")
If epage="" Then epage=1
For i=(epage-1)*pagesize To epage*pagesize-1
If i>UBound(aResults,2) Or i<0 Then Exit for
%>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<%j=1%>
<tr>
<%do while not aResults.eof%>
<td align=middle valign=center>
<a href=kanbao.asp?id=<%=aResults(0,i)%> target="_blank"><img src="upload/<%=aResults(6,i)%>" alt="<%=aResults(1,i)%>" width="160" height="120" border="0" align="absmiddle"><br><%=aResults(1,i)%></a><br><br><br>
<%If j Mod 3 = 0 Then%>
</td>
<%
j = j + 1
aResults.movenext
end if
Loop
%>
</tr>
</table>
<%
Next
If numb>pagesize Then
fenye="<a href=2009bb2.asp?page=1>首页</a> "
fenye=fenye&"<a href=2009bb2.asp?page="&epage-1&" title="&epage-1&">前页</a> "
fenye=fenye&"<a href=2009bb2.asp?page="&epage+1&" title="&epage+1&">后页</a> "
fenye=fenye&"<a href=2009bb2.asp?page="&pagecount&">末页</a> "
fenye=fenye&"总页数"&pagecount&",当前页"&epage&",总记录为:"&numb
response.write fenye
End if
%>
现在我需要将这个结果分三列自动换行显示,我知道是do while not aResults.eof的问题,但是应该怎么写才正确?请高手指点!
问题不在循环的写法上,循环写的没错。是aResults.eof的问题,不知道怎么写。去除do while not aResults.eof,aResults.movenext ,loop就可以,只是没有分列。
另外一个页面,aResults=application("data")data的代码:
<!--#include file="conn.asp"-->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head>
<body>
<%
sql="select * from news where BigclassName='宝宝秀'and SmallClassName='2009年宝宝秀' and imagenum>0 and infotime>='2008-11-1' and infotime<'2009-11-1' order by id asc"
Set rs=conn.execute(sql)
If rs.eof And rs.bof Then
response.Write("没有查找到您要的记录")
response.End
Else
aResults=rs.getrows()'取出数据放入数组ROW中
application("data")=aResults
Set rs=nothing
conn.close '关闭数据库
End IF
%>
<iframe src="2009bb2.asp" width="1000" height="1300" border="0" frameborder="0" framespacing="0" marginheight="0" marginwidth="0" scrolling="yes"></iframe>
</body> 展开
5个回答
展开全部
其实很简单的,楼主只是循环表格那里有点问题,我尝试写了一下,顺便改进了分页功能.
'修改后的代码
aResults=application("data")
Dim i,row,pagesize,epage,numb,pagecount,fenye
pagesize=18 '每页条数
numb=UBound(aResults,2)+1 '总记录行数
If numb Mod pagesize = 0 Then '判断总页数
pagecount=Int(numb/pagesize)
Else
pagecount=Int(numb/pagesize)+1
End If
epage=request.querystring("page")
If epage="" Then epage=1
%>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<%
j=1
For i=(epage-1)*pagesize To epage*pagesize-1
If i>UBound(aResults,2) Or i<0 Then Exit for
%>
<td align=middle valign=center>
<a href=kanbao.asp?id=<%=aResults(0,i)%> target="_blank"><img src="upload/<%=aResults(6,i)%>" alt="<%=aResults(1,i)%>" width="160" height="120" border="0" align="absmiddle"><br><%=aResults(1,i)%></a><br><br><br>
<%
If j Mod 3 = 0 Then%>
<%
response.Write("<tr></tr>")
end if
j=j+1
Next
%>
</td>
</tr>
</table>
<%
If numb>pagesize Then
fenye="<a href=example.asp?page=1>首页</a> "
if epage=1 then
fenye=fenye&"前页 "
else
fenye=fenye&"<a href=example.asp?page="&epage-1&" title="&epage-1&">前页</a> "
end if
if pagecount=cint(epage) then
fenye=fenye&"后页 "
else
fenye=fenye&"<a href=example.asp?page="&epage+1&" title="&epage+1&">后页</a> "
end if
fenye=fenye&"<a href=example.asp?page="&pagecount&">末页</a> "
fenye=fenye&"总页数"&pagecount&",当前页"&epage&",总记录为:"&numb
response.write fenye
End if
%>
'修改后的代码
aResults=application("data")
Dim i,row,pagesize,epage,numb,pagecount,fenye
pagesize=18 '每页条数
numb=UBound(aResults,2)+1 '总记录行数
If numb Mod pagesize = 0 Then '判断总页数
pagecount=Int(numb/pagesize)
Else
pagecount=Int(numb/pagesize)+1
End If
epage=request.querystring("page")
If epage="" Then epage=1
%>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<%
j=1
For i=(epage-1)*pagesize To epage*pagesize-1
If i>UBound(aResults,2) Or i<0 Then Exit for
%>
<td align=middle valign=center>
<a href=kanbao.asp?id=<%=aResults(0,i)%> target="_blank"><img src="upload/<%=aResults(6,i)%>" alt="<%=aResults(1,i)%>" width="160" height="120" border="0" align="absmiddle"><br><%=aResults(1,i)%></a><br><br><br>
<%
If j Mod 3 = 0 Then%>
<%
response.Write("<tr></tr>")
end if
j=j+1
Next
%>
</td>
</tr>
</table>
<%
If numb>pagesize Then
fenye="<a href=example.asp?page=1>首页</a> "
if epage=1 then
fenye=fenye&"前页 "
else
fenye=fenye&"<a href=example.asp?page="&epage-1&" title="&epage-1&">前页</a> "
end if
if pagecount=cint(epage) then
fenye=fenye&"后页 "
else
fenye=fenye&"<a href=example.asp?page="&epage+1&" title="&epage+1&">后页</a> "
end if
fenye=fenye&"<a href=example.asp?page="&pagecount&">末页</a> "
fenye=fenye&"总页数"&pagecount&",当前页"&epage&",总记录为:"&numb
response.write fenye
End if
%>
展开全部
<%do while not aResults.eof%>
<td align=middle valign=center>
<a href=kanbao.asp?id=<%=aResults(0,i)%> target="_blank"><img src="upload/<%=aResults(6,i)%>" alt="<%=aResults(1,i)%>" width="160" height="120" border="0" align="absmiddle"><br><%=aResults(1,i)%></a><br><br><br>
<%If j Mod 3 = 0 Then%>
</td>
<%
j = j + 1
aResults.movenext
end if
Loop
%>
改成下面的:
<%do while not aResults.eof%>
<td align=middle valign=center>
<a href=kanbao.asp?id=<%=aResults(0,i)%> target="_blank"><img src="upload/<%=aResults(6,i)%>" alt="<%=aResults(1,i)%>" width="160" height="120" border="0" align="absmiddle"><br><%=aResults(1,i)%></a>
</td>
<%
if j Mod 3 = 0 Then response.write "</tr><tr>"
<%
j = j + 1
aResults.movenext
Loop
%>
<td align=middle valign=center>
<a href=kanbao.asp?id=<%=aResults(0,i)%> target="_blank"><img src="upload/<%=aResults(6,i)%>" alt="<%=aResults(1,i)%>" width="160" height="120" border="0" align="absmiddle"><br><%=aResults(1,i)%></a><br><br><br>
<%If j Mod 3 = 0 Then%>
</td>
<%
j = j + 1
aResults.movenext
end if
Loop
%>
改成下面的:
<%do while not aResults.eof%>
<td align=middle valign=center>
<a href=kanbao.asp?id=<%=aResults(0,i)%> target="_blank"><img src="upload/<%=aResults(6,i)%>" alt="<%=aResults(1,i)%>" width="160" height="120" border="0" align="absmiddle"><br><%=aResults(1,i)%></a>
</td>
<%
if j Mod 3 = 0 Then response.write "</tr><tr>"
<%
j = j + 1
aResults.movenext
Loop
%>
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
<%
aResults=application("data")
Dim i,row,pagesize,epage,numb,pagecount,fenye
numb=UBound(aResults,2)+1 '总记录行数
pagesize=18 '每页条数
If numb Mod pagesize = 0 Then '判断总页数
pagecount=Int(numb/pagesize)
Else
pagecount=Int(numb/pagesize)+1
End If
epage=request.querystring("page")
If epage="" Then epage=1
For i=(epage-1)*pagesize To epage*pagesize-1
If i>UBound(aResults,2) Or i<0 Then Exit for
%>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<%j=1%>
<tr>
<%do while not aResults.eof%>
<td align=middle valign=center>
<a href=kanbao.asp?id=<%=aResults(0,i)%> target="_blank"><img src="upload/<%=aResults(6,i)%>" alt="<%=aResults(1,i)%>" width="160" height="120" border="0" align="absmiddle"><br><%=aResults(1,i)%></a><br><br><br>
</td>
<%If j Mod 3 = 0 Then%>
</tr><tr>
<% end if
j = j + 1
aResults.movenext
Loop
%>
</tr>
</table>
<%
Next
If numb>pagesize Then
fenye="<a href=2009bb2.asp?page=1>首页</a> "
fenye=fenye&"<a href=2009bb2.asp?page="&epage-1&" title="&epage-1&">前页</a> "
fenye=fenye&"<a href=2009bb2.asp?page="&epage+1&" title="&epage+1&">后页</a> "
fenye=fenye&"<a href=2009bb2.asp?page="&pagecount&">末页</a> "
fenye=fenye&"总页数"&pagecount&",当前页"&epage&",总记录为:"&numb
response.write fenye
End if
%>
aResults=application("data")
Dim i,row,pagesize,epage,numb,pagecount,fenye
numb=UBound(aResults,2)+1 '总记录行数
pagesize=18 '每页条数
If numb Mod pagesize = 0 Then '判断总页数
pagecount=Int(numb/pagesize)
Else
pagecount=Int(numb/pagesize)+1
End If
epage=request.querystring("page")
If epage="" Then epage=1
For i=(epage-1)*pagesize To epage*pagesize-1
If i>UBound(aResults,2) Or i<0 Then Exit for
%>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<%j=1%>
<tr>
<%do while not aResults.eof%>
<td align=middle valign=center>
<a href=kanbao.asp?id=<%=aResults(0,i)%> target="_blank"><img src="upload/<%=aResults(6,i)%>" alt="<%=aResults(1,i)%>" width="160" height="120" border="0" align="absmiddle"><br><%=aResults(1,i)%></a><br><br><br>
</td>
<%If j Mod 3 = 0 Then%>
</tr><tr>
<% end if
j = j + 1
aResults.movenext
Loop
%>
</tr>
</table>
<%
Next
If numb>pagesize Then
fenye="<a href=2009bb2.asp?page=1>首页</a> "
fenye=fenye&"<a href=2009bb2.asp?page="&epage-1&" title="&epage-1&">前页</a> "
fenye=fenye&"<a href=2009bb2.asp?page="&epage+1&" title="&epage+1&">后页</a> "
fenye=fenye&"<a href=2009bb2.asp?page="&pagecount&">末页</a> "
fenye=fenye&"总页数"&pagecount&",当前页"&epage&",总记录为:"&numb
response.write fenye
End if
%>
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
<%do while not aResults.eof%>
<td align=middle valign=center>
<a href=kanbao.asp?id=<%=aResults(0,i)%> target="_blank"><img src="upload/<%=aResults(6,i)%>" alt="<%=aResults(1,i)%>" width="160" height="120" border="0" align="absmiddle"><br><%=aResults(1,i)%></a><br><br><br>
<%If j Mod 3 = 0 Then%>
</td>
<%
j = j + 1
aResults.movenext
end if
Loop
%>
改为
<%do while not aResults.eof%>
<td align=middle valign=center>
<a href=kanbao.asp?id=<%=aResults(0,i)%> target="_blank"><img src="upload/<%=aResults(6,i)%>" alt="<%=aResults(1,i)%>" width="160" height="120" border="0" align="absmiddle"><br><%=aResults(1,i)%></a>
</td>
<%If j Mod 3 = 0 Then
response.Write "</tr><tr>"
end if
j = j + 1
aResults.movenext
end if
Loop
%>
<td align=middle valign=center>
<a href=kanbao.asp?id=<%=aResults(0,i)%> target="_blank"><img src="upload/<%=aResults(6,i)%>" alt="<%=aResults(1,i)%>" width="160" height="120" border="0" align="absmiddle"><br><%=aResults(1,i)%></a><br><br><br>
<%If j Mod 3 = 0 Then%>
</td>
<%
j = j + 1
aResults.movenext
end if
Loop
%>
改为
<%do while not aResults.eof%>
<td align=middle valign=center>
<a href=kanbao.asp?id=<%=aResults(0,i)%> target="_blank"><img src="upload/<%=aResults(6,i)%>" alt="<%=aResults(1,i)%>" width="160" height="120" border="0" align="absmiddle"><br><%=aResults(1,i)%></a>
</td>
<%If j Mod 3 = 0 Then
response.Write "</tr><tr>"
end if
j = j + 1
aResults.movenext
end if
Loop
%>
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
用变量循环td,为3时tr
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询