注册 登录
编程论坛 ASP技术论坛

如此循环不出效果,郁闷!

lele2007 发布于 2008-04-13 15:24, 698 次点击
<table width="972" border="0" cellpadding="3" cellspacing="0">
<%
if rs.bof and rs.eof then
for i=1 to 3
%>
<tr>
<% for ii=1 to 10 %>
   <td>
 <a href="javascript:alert('点击申请友情链接')"><img src="../friends_file/logo/friends_logo.gif" width="88" height="31" border="0"  lt="点击申请友情链接" /></a>
 </td>
 <% next %>
    </tr>
 <%
 next
 end if
 %>
<%
do while not rs.eof
for i=1 to 3
%>
  <tr>
  <% for ii=1 to 10 %>
    <td>
 <a href="<%=rs("f_url")%>"><img src="../friends_file/logo/<%=rs("f_logo")%>" width="88" height="31" border="0" alt="<%=rs("f_alt")%>" /></a>
 </td>
 <% next %>
    </tr>
    <%
 next
 rs.movenext
 loop
 %>
</table>
----------------------------------------------------------------------------------------
以上是源代码!但是所实现的功能不是想要的!初学者只知道简单的,而我想实现的效果是:如果数据库里没有记录则执行:
<tr>
<% for ii=1 to 10 %>
   <td>
 <a href="javascript:alert('点击申请友情链接')"><img src="../friends_file/logo/friends_logo.gif" width="88" height="31" border="0"  lt="点击申请友情链接" /></a>
 </td>
 <% next %>
    </tr>
 <%
 next
 end if
 %>
这段代码!如果数据库有记录则执行读取数据库的内容然后显示在页面里!但是我是用一个3行10列的表格,只要数据库里有一条记录就会填满整个3行10列的表格,就是每个单元格里都会显示同一个信息,我想实现的是,一行有:10个记录共3行,如果数据库里没有这么多记录则显示数据库已有的记录,而不够则用<a href="javascript:alert('点击申请友情链接')"><img src="../friends_file/logo/friends_logo.gif" width="88" height="31" border="0"  lt="点击申请友情链接" /></a>这个来代替!但是代码不知道应该怎么写!请教一下大家!很感谢!
2 回复
#2
tianyu1232008-04-14 12:55
给你个参考:
程序代码:
<table border=0 cellpadding=0 cellspacing=1 bgcolor="#ECECEC">
<%
dim num,sum
num=0
sum=15 'sum为数据库中数据的总记录数
for i=1 to 3
%>
<tr bgcolor="#FFFFFF">
<%
  for j=1 to 10
  num=num+1
%>
<td width="80" height="30" align="center">
<%
  if num<=sum then
  Response.Write i&j
  else
  Response.Write"点击申请"
  end if
  next
%>
</td>
</tr>
<%
next
%>
</table>
#3
lele20072008-04-14 13:10
谢谢了!明白了!我试着写一下!谢谢你!
1