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

在下面的代码中,怎样才能实现横向和纵向的循环(比如:3行2列)?多谢!

tepnidh 发布于 2012-02-02 13:25, 562 次点击
<!--#include file="connW.asp" -->
<%
Set ad = Server.CreateObject ("ADODB.Recordset")
sql = "Select top 5 * from yhgl  ORDER BY id DESC"
ad.Open sql,conn,1,1
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>无标题文档</title>
<style type="text/css">
<!--
.STYLE1 {font-size: 12px}
-->
</style>
</head>
<body>
<table width="300" border="1" cellspacing="0" cellpadding="0">
  <%
if ad.EOF and ad.BOF then
response.write
else
Do Until ad.EOF %>
   <tr>
    <td align="center"><%= ad("name") %></td>
    <td align="center"><%= ad("sex") %></td>
    <td align="center"><%= ad("QQ") %></td>
  </tr>
  <% ad.MoveNext
Loop
end if
%>
</table>
</body>
</html>
6 回复
#2
tepnidh2012-02-02 15:26
帮帮我吧!!
#3
yms1232012-02-02 16:24
不明白LZ要求的两列是什么样式。
行列循环只要遵守外行内列的原理即可
比如3行两列
<%
  Dim r,c
  Response.Write "<table>"
  For r=0 To 3'循环3行
      Response.Write "<tr>"
      For c=0 To 2'循环2列
          Response.Write "<td>"
          Response.Write "第"&r&"行,第"&c&"列"
          Response.Write "</td>"
      Next
      Response.Write "</tr>"
  Next
  Response.Write "</table>"
%>
#4
tepnidh2012-02-02 21:23
谢谢您的帮助!能否在原代码中,帮我改改,我的意思是这样的:

第1行第1列;第1行第2列;
第2行第1列;第2行第2列;
第3行第1列;第3行第2列;

如:
张  三,男,1234567;李  四,男,0123456;
刘  娟,女,2345678;王  丽,女,5678903;
赵  新,男,5678934;钱  妍,女,6789045;
。。。。。。。。。。。。。。。。。。。。
#5
tepnidh2012-02-02 21:25
回复 3楼 yms123
谢谢您的帮助!能否在原代码中,帮我改改,我的意思是这样的:

第1行第1列;第1行第2列;
第2行第1列;第2行第2列;
第3行第1列;第3行第2列;

如:
张  三,男,1234567;李  四,男,0123456;
刘  娟,女,2345678;王  丽,女,5678903;
赵  新,男,5678934;钱  妍,女,6789045;
。。。。。。。。。。。。。。。。。。。。
#6
yms1232012-02-02 22:02
<!--#include file="connW.asp" -->
<%
Set ad = Server.CreateObject ("ADODB.Recordset")
sql = "Select top 5 * from yhgl  ORDER BY id DESC"
ad.Open sql,conn,3,3
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>无标题文档</title>
<style type="text/css">
<!--
.STYLE1 {font-size: 12px}
-->
</style>
</head>
<body>
<table width="300" border="1" cellspacing="0" cellpadding="0">
  <%
if ad.EOF and ad.BOF then
response.write
else
Dim tHtml,c
c=0
tHtml=""
Do Until ad.EOF
    tHtml=tHtml&"<td align='center' >"&ad("name")&"</td>"
    tHtml=tHtml&"<td align='center' >"&ad("sex")&"</td>"
    tHtml=tHtml&"<td align='center'>"&ad("QQ")&"</td>"
    c=c+1
    if c>2 Or c=2 Then
       tHtml="<tr>"&tHtml&"</tr>"
       c=0
    End IF
  ad.MoveNext
Loop
Response.Write tHtml
end if
%>
</table>
</body>
</html>
#7
tepnidh2012-02-03 08:50
回复 6楼 yms123
多谢!
1