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

循环问题?????帮忙!!

xiaoyangyjs 发布于 2008-01-10 21:54, 1745 次点击
<%for i=0 to 3%>
<%q=0
do while not rs.eof and q<2%>
<table width="279" border="1" cellspacing="10">
  <tr>
    <td rowspan="3"><img width="90" height="80"src="images/<%=rs("img")%>"></td>
    <td width="200"><img src="images/w.gif"><font class="STYLE10"><%=rs("productname")%></td>
  </tr>
  <tr>
    <td><span class="STYLE16"><font class="STYLE10">市场价:<%=rs("scj")%></span></td>
  </tr>
  <tr>
    <td><span class="STYLE16"><font class="STYLE10">会员价:<%=rs("hyj")%></span></td>
  </tr>
</table>
<%rs.movenext
      q=q+1
      loop%>
      <%next%>

我的最终目的是想在一行上显示二条记录,然后在第二行再显示二条记录,这样循环下去,而序号是这样的,第一行是1 . 2 而在第二行上是3 . 4 这样大家应该明白我说的什么吧!
希望可以帮我解决一下!!不甚感激!!!
10 回复
#2
madpbpl2008-01-10 22:04
试试这样
<table width="279" border="1" cellspacing="10">
<%for i=0 to 3%>
<%q=1
do while not rs.eof %>
<%if q>1and q mod 2 =1 then response.write "</tr><tr>" end if%>

  <tr>
    <td rowspan="3"><img width="90" height="80"src="images/<%=rs("img")%>"></td>
    <td width="200"><img src="images/w.gif"><font class="STYLE10"><%=rs("productname")%></td>
    <td><span class="STYLE16"><font class="STYLE10">市场价:<%=rs("scj")%></span></td>
      <td><span class="STYLE16"><font class="STYLE10">会员价:<%=rs("hyj")%></span></td>
  </tr>

<%rs.movenext
      q=q+1
      loop%>
      <%next%>
</table>
#3
xiaoyangyjs2008-01-11 11:15
这样也不行,显示不出那个效果<table width="200" border="0" cellpadding="0" cellspacing="0">
 <%for i=0 to 3%>
  
  <tr>
   
    <%q=0
do while not rs.eof and q<2%>
    <td>
    <table width="279" border="0" cellpadding="0" cellspacing="10">
      <tr>
        <td rowspan="3"><img width="90" height="80"src="images/<%=rs("img")%>"></td>
        <td width="200"><img src="images/w.gif"><font class="STYLE10"><%=rs("productname")%></td>
      </tr>
      <tr>
        <td><span class="STYLE16"><font class="STYLE10">市场价:<%=rs("scj")%></span></td>
      </tr>
      <tr>
        <td><span class="STYLE16"><font class="STYLE10">会员价:<%=rs("hyj")%></span></td>
      </tr>
    </table>
    </td>
    <%rs.movenext
      q=q+1
      loop%>
    
    
  </tr>
    <%next%>
  
</table>


我把他改成这样,在第一页可以显示想要的效果,可是第二页之后效果很差???可以给我看看这段代码吗???
#4
madpbpl2008-01-11 18:29
我写的是对行循环,而楼主的写法是对列循环
#5
xiaoyangyjs2008-01-11 19:01
是的,我是先对列循环再对行循环的,这就是我的意思,可是效果不是我想要的,怎么办呢???
我想的结果是这样的,在第一行显示二列,第二行显示二列,如果是数据的话,那第一行就是1和2,而第二行就是3和4,而在数据库中他是按顺序读出来,就是这样的效果,正是我所要的.
那这样效果应该怎么样写呢,到底我这样写对吗??拜托指点一下吧??
#6
madpbpl2008-01-11 19:48
这样呢
<table width="279" border="1" cellspacing="10">
<tr>
<%q=1
do while not rs.eof %>
<%if q>1and q mod 2 =1 then response.write "</tr><tr>" end if%>
   <td><img width="90" height="80"src="images/<%=rs("img")%>"><br>
    <img src="images/w.gif"><font class="STYLE10"><%=rs("productname")%><br>
    <span class="STYLE16"><font class="STYLE10">市场价:<%=rs("scj")%></span><br>>
    <span class="STYLE16"><font class="STYLE10">会员价:<%=rs("hyj")%></span></td>
 <%rs.movenext
      q=q+1
      loop%>
      </tr>
</table>
#7
xiaoyangyjs2008-01-11 20:09
这样是可以的,可是和我的那个一样在分页后的第二页面,效果也不行,也有许多重复的,后面的好像就是乱排一样
#8
hangxj2008-01-12 17:50
<table width="279" border="1" cellspacing="10">
<tr>
<%q=0
do while not rs.eof %>
   <td><img width="90" height="80"src="images/<%=rs("img")%>"><br>
    <img src="images/w.gif"><font class="STYLE10"><%=rs("productname")%><br>
    <span class="STYLE16"><font class="STYLE10">市场价:<%=rs("scj")%></span><br>>
    <span class="STYLE16"><font class="STYLE10">会员价:<%=rs("hyj")%></span></td>
<%rs.movenext
      q=q+1
      loop%>
<%if  q mod 2 =0 then response.write "</tr><tr>" end if%>
</table>

试下这样
#9
xiaoyangyjs2008-01-13 15:19
hangxj的好像有问题吧,最后的那个if  语句if  q mod 2 =0 then response.write "</tr><tr>" end if是不是应该放在loop之前吧,不然好像这句话没有用似的,因为他一直在循环,一直到循环结束才判断,这不是我所要的结果,其实这种效果也是可以的,只是这样显示之后,分页就好像不怎么好写了,现在觉得自己比较菜,望各位帮一忙,小弟先谢谢了.
<table width="279" border="1" cellspacing="10">
<tr>
<%q=0
do while not rs.eof %>
   <td><img width="90" height="80"src="images/<%=rs("img")%>"><br>
    <img src="images/w.gif"><font class="STYLE10"><%=rs("productname")%><br>
    <span class="STYLE16"><font class="STYLE10">市场价:<%=rs("scj")%></span><br>>
    <span class="STYLE16"><font class="STYLE10">会员价:<%=rs("hyj")%></span></td>
<%rs.movenext
      q=q+1
if  q mod 2 =0 then response.write "</tr><tr>" end if
      loop%>
</table>
#10
xiaoyangyjs2008-01-15 20:52
这问题我已经解决了,谢谢大家帮忙!
#11
hangxj2008-01-20 15:55
额,的确,呵呵~~ 大意了
1