如何将从数据库循环提取的图片分成5行2列显示?

batistuta97 2005-04-29 10:12:28
我现在的代码如下:
<%
for i=1 to rs.pagesize
If rs.EOF Then Exit For
filepath=rs("filepath")
id=rs("id")
ext=rs("picext")
file=filepath+cstr(id)+"."+ext
file2=filepath+cstr(id+1)+"."+ext
%>
<tr bgcolor="#7c7c7c">
<td height="80" width="80">
<a href="work_011.asp?file=<%=file%>" target="mainFrame"><img src="<%=file%>" width="80" height="80"></a>
</td>
<td height="80" width="80">
<a href="work_011.asp?file=<%=file2%>" target="mainFrame"><img src="<%=file2%>" width="80" height="80"></a>
</td>
</tr>
<%
rs.movenext
next

%>
现在这样倒是可以显示成5行2列,但是图片就会重复出现,该怎么处理?谢谢各位了
...全文
205 17 打赏 收藏 转发到动态 举报
写回复
用AI写文章
17 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
不好意思啊,有事情没注意你这个,分页显示错误很容易想的就是计算失误的在pagesize和page的换算,今天比较忙,qq的朋友就对不住了
batistuta97 2005-04-29
  • 打赏
  • 举报
回复
davery() 你的这个显示出来图片都是每行两个一样的哦?
chang1216(最少两瓶)你的我等下回来研究研究,先吃饭去了
谢谢各位了:)
davs 2005-04-29
  • 打赏
  • 举报
回复
补充一下,如果个数为奇数,这个页面排列就不整齐啦,以下是完整的:
<%
for i=1 to rs.pagesize
filepath=rs("filepath")
id=rs("id")
ext=rs("picext")
file=filepath+cstr(id)+"."+ext
if i mod 2 = 1 then
%>

<tr bgcolor="#7c7c7c">
<%end if%>

<td height="80" width="80">
<a href="work_011.asp?file=<%=file%>" target="mainFrame"><img src="<%=file%>" width="80" height="80"></a>
</td>
<%if i mod 2 = 0 then%>
</tr>
<%
end if
rs.movenext
If rs.EOF Then Exit For
next
if i mod 2=1 then
response.write("<td height="80" width="80"></td></tr>")
end if
%>

davs 2005-04-29
  • 打赏
  • 举报
回复
呵呵,这是我的

<%
for i=1 to rs.pagesize
If rs.EOF Then Exit For
filepath=rs("filepath")
id=rs("id")
ext=rs("picext")
file=filepath+cstr(id)+"."+ext
'file2=filepath+cstr(id+1)+"."+ext
if i mod 2 = 1 then
%>

<tr bgcolor="#7c7c7c">
<%end if%>

<td height="80" width="80">
<a href="work_011.asp?file=<%=file%>" target="mainFrame"><img src="<%=file%>" width="80" height="80"></a>
</td>
<%if i mod 2 = 0 then%>
</tr>
<%
end if
rs.movenext
next

%>
chang1216 2005-04-29
  • 打赏
  • 举报
回复
<%

set rscyc=server.CreateObject("adodb.recordset")
sqlnew="select * from youtable where "
rscyc.open sqlnew,conn,3,1
'response.write sqlnew
if not rscyc.eof then
%>
<tr>
<%
count1=0
while not rscyc.eof
count1=count1+1
%>
<td width="24%" align="center"><a href=upload/manage/<%=rscyc("file_new_filename")%> target="new" title="<%=rscyc("File_new_Discription")%>"><img src="upload/manage/<%=rscyc("file_new_filename")%>" height=100 width=100 border=0></a>
</td>
<%


if count1 mod 5=0 then
response.write("</tr><tr >")
end if
rscyc.movenext
wend
rscyc.movefirst
count1=abs(5-count1)
do while count1=5
count1=count1+1
response.write("<td></td>")
loop
%>
自己改一下数字就可以了 然后对这个结果集 进行分页显示
batistuta97 2005-04-29
  • 打赏
  • 举报
回复
兔子。。。。。。
batistuta97 2005-04-29
  • 打赏
  • 举报
回复
厚道的方法没有效果哦
兔子的倒是可以,但是还有个问题,我有12条记录,分页显示,下一页会把上一页的一半内容显示出来
是那里的问题?
batistuta97 2005-04-29
  • 打赏
  • 举报
回复
先谢谢各位了,我先试试
  • 打赏
  • 举报
回复
<%
for i=1 to rs.pagesize
If rs.EOF Then Exit For
filepath=rs("filepath")
id=rs("id")
ext=rs("picext")
file=filepath+cstr(id)+"."+ext

%>
<tr bgcolor="#7c7c7c">
<td height="80" width="80">
<a href="work_011.asp?file=<%=file%>" target="mainFrame"><img src="<%=file%>" width="80" height="80"></a>
</td>
<% rs.movenext %>
<% if not rs.eof then %>
filepath=rs("filepath")
id=rs("id")
ext=rs("picext")
file=filepath+cstr(id)+"."+ext
<td height="80" width="80">
<a href="work_011.asp?file=<%=file%>" target="mainFrame"><img src="<%=file%>" width="80" height="80"></a>
</td>
<% else
exit for
end if
%>
</tr>
<%
rs.movenext
next

%>
刚才有点小错误
iexapl 2005-04-29
  • 打赏
  • 举报
回复
用mod
  • 打赏
  • 举报
回复
<%
for i=1 to rs.pagesize
If rs.EOF Then Exit For
filepath=rs("filepath")
id=rs("id")
ext=rs("picext")
file=filepath+cstr(id)+"."+ext

%>
<tr bgcolor="#7c7c7c">
<td height="80" width="80">
<a href="work_011.asp?file=<%=file%>" target="mainFrame"><img src="<%=file%>" width="80" height="80"></a>
</td>
<% rs.movenext %>
<% if not rs.eof then %>
filepath=rs("filepath")
id=rs("id")
ext=rs("picext")
file=filepath+cstr(id)+"."+ext
<td height="80" width="80">
<a href="work_011.asp?file=<%=file2%>" target="mainFrame"><img src="<%=file2%>" width="80" height="80"></a>
</td>
<% else
exit for
end if
%>
</tr>
<%
rs.movenext
next

%>
menrock 2005-04-29
  • 打赏
  • 举报
回复
<tr bgcolor="#7c7c7c">
<%
for i=1 to rs.pagesize
If rs.EOF Then Exit For
filepath=rs("filepath")
id=rs("id")
ext=rs("picext")
file=filepath+cstr(id)+"."+ext
file2=filepath+cstr(id+1)+"."+ext
%>
<td height="80" width="80">
<a href="work_011.asp?file=<%=file%>" target="mainFrame"><img src="<%=file%>" width="80" height="80"></a>
</td>
<td height="80" width="80">
<a href="work_011.asp?file=<%=file2%>" target="mainFrame"><img src="<%=file2%>" width="80" height="80"></a>
</td>
<%rs.movenext
if i mod 2=0 and not rs.eof then
response.write("</tr><tr bgcolor='#7c7c7c'>")
else
resposne.write("</tr>")
end if
next

%>
batistuta97 2005-04-29
  • 打赏
  • 举报
回复
今天下午没时间弄了,弄好就结贴哈
  • 打赏
  • 举报
回复
<%
dim i,j
if not rs.eof then
rs.PageSize=8 '这里要改成10
count=rs.PageCount
rs.AbsolutePage=page1
end if
j=0
%>
<% if page1=1 then %>
第一页
</td>
<td>上一页</td>
<% if page1<Count then %>
<td><a href='picdisplay1.asp?Page=<% =(page1+1) %>&foldernum1=<% =foldernum1 %>'>下一页</a></td>
<td><a href='picdisplay1.asp?Page=<% =Count%>&foldernum1=<% =foldernum1 %>'>最后一页</a></td>
<% else %>
<td>下一页</td>
<td>最后一页</td>
<% end if %>
<% else %>
<% if page1<Count then %>
<td><a href='picdisplay1.asp?Page=1&foldernum1=<% =foldernum1 %>'>第一页</a></td>
<td><a href='picdisplay1.asp?Page=<% =(page1-1)%>&foldernum1=<% =foldernum1 %>'>上一页</a></td>
<td><a href='picdisplay1.asp?Page=<% =(page1+1)%>&foldernum1=<% =foldernum1 %>'>下一页</a></td>
<td><a href='picdisplay1.asp?Page=<% =Count%>&foldernum1=<% =foldernum1 %>'>最后一页</a></td>
<% else %>
<td><a href='picdisplay1.asp?Page=1&foldernum1=<% =foldernum1 %>'>第一页</a></td>
<td><a href='picdisplay1.asp?Page=<% =(page1-1)%>&foldernum1=<% =foldernum1 %>'>上一页</a></td>
<td>下一页</td>
<td>最后一页</td>
<% end if %>
<% end if %>

<table>

<%

while(not rs.eof and j<2) '这里改成5就是5行了
%>
<tr>
<%
i=0
while(i<=3 and not rs.eof) '这里改成1就是2列
%>
<td>
<input type=checkbox name='checKbox' value='<% path=name & "/" & "photos" & "/" & rs("picname")
response.write rs("picname")
%>' />
</td>
<td><center>
<a href='<% =path & ".jpg" %>' target=_blank>
<img src='<% =path & "a.jpg" %>' border=0>
</a></center>
</td>
<%
rs.movenext
i=i+1
wend
j=j+1
%>
</tr>
<%
wend
rs.close
set rs=nothing

%>
</table>
  • 打赏
  • 举报
回复
我有个2行4列的你要么?
batistuta97 2005-04-29
  • 打赏
  • 举报
回复
分不够再加!!!
batistuta97 2005-04-29
  • 打赏
  • 举报
回复
各位高手,我对循环简直头晕,能帮忙弄个完整可用的嘛?谢了

28,406

社区成员

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

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