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

循环语句该怎么改 ?

myou841103 发布于 2010-10-20 21:00, 405 次点击
表1
与户主关系     妻子   儿子  父亲  母亲   儿子   
姓名            a      b     c      d      e

每个表格显示1列标题和5列数据 满了另起表格  
表2
与户主关系     儿媳   女儿                     没数据的留空
姓名            a      b     

该怎么实现 ?


下面我写了点代码 ,不知道怎么写下去





<table  id=data width="800" border="1">


  <tr>
    <td>与户主关系</td>
    <%j=5:response.write ( "<td>")

i=0
while not rs.eof
 if (i mod j)=0 then
%>
<%=rs("关系")%>
<%response.write "</TD>"%>
<%'response.write ( "<td>")%>
<%
i=i+1
if (i mod j)=0 then response.write "</TR>"
%>
<tr>
    <td>姓名</td>
    <%j=5:response.write ( "<td>")

i=0
while not rs.eof
 if (i mod j)=0 then
%>
<%=rs("cmname")%>
<%response.write "</TD>"%>
<%'response.write ( "<td>")%>
<%
i=i+1
if (i mod j)=0 then response.write "</TR>"
%>

<%response.write "<p></p>"%>

<%
end if
rs.movenext
wend
%>

</table>

3 回复
#2
dzt00012010-10-21 11:09
程序代码:
<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<%
rs1
=split("1,2,3,4,5,6,7,8",",")
rs2
=split("A,B,C,D,E,F,G,H",",")
TotalCount
=ubound(rs1)

redim ArrayList(TotalCount,1)     '定义二维数组
for i=0 to TotalCount
ArrayList(i,
0)=rs1(i)
ArrayList(i,
1)=rs2(i)
next

'你可以将数据记录先放入数组

RowSetup
=5    '每行设定的列数
TotalRow=Abs(Int(TotalCount/RowSetup*(-1)))     '计算分行的数量

response.write
"<table border=""1"">"

for i=1 to TotalRow
    response.write
"<tr><td>行"&i&"</td>"
   
for j=1 to RowSetup
        
if (i-1)*RowSetup+j-1>TotalCount then
            response.write
"<td> </td>"
        
else
            response.write
"<td>"&ArrayList((i-1)*RowSetup+j-1,0)&"</td>"
        
end if
   
next

    response.write
"<tr><td>行"&i&"</td>"
   
for j=1 to RowSetup
        
if (i-1)*RowSetup+j-1>TotalCount then
            response.write
"<td> </td>"
        
else
            response.write
"<td>"&ArrayList((i-1)*RowSetup+j-1,1)&"</td>"
        
end if
   
next
next

response.write
"</table>"
%>

 上面是我以前写的一个代码,你可以参考一下

[ 本帖最后由 dzt0001 于 2010-10-21 11:11 编辑 ]
#3
myou8411032010-10-21 20:47
回复 2楼 dzt0001
rs1=split("1,2,3,4,5,6,7,8",",")
rs2=split("A,B,C,D,E,F,G,H",",")
你是用,来分割,
那如果是rs("关系")取代1,2,3...,rs("cmname")取代A,B,C...该如何写呢?
#4
dzt00012010-10-22 09:22
程序代码:
Rs.Open sql,Conn,1,3
TotalCount=Rs.Recordcount     '获取数据数量
redim ArrayList(TotalCount,1)     '定义二维数组
i=0
Do While Not Rs.EOF
ArrayList(i,0)=Rs("关系")
ArrayList(i,1)=Rs("姓名")
i=i+1
Rs.MoveNext
loop
Rs.Close

 

 
 
1