1. 论坛系统升级为Xenforo,欢迎大家测试!
    排除公告

菜鸟求救,帮我改一段代码

本帖由 streamlet2005-10-13 发布。版面名称:前端开发

  1. streamlet

    streamlet New Member

    注册:
    2005-10-13
    帖子:
    11
    赞:
    0
    帮我把下面的一段分类代码改成两列显示,现在是一列显示的,分类类似http://www.godele.com/这个站上的分类




    <!--#include file="conn.asp"-->
    <!--#include file="webconfig.asp"-->
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <title>无标题文档</title>
    <style type="text/css">
    <!--
    .style1 { color: #000000;
    font-size: 14px;
    font-weight: bold;
    }
    .style4 { color: #000000;
    font-size: 12px;}

    td{ LINE-HEIGHT: 130%; }

    a:link {
    color: #333333; text-decoration:none
    }
    a:visited {
    color: #333333; text-decoration: none
    }
    a:hover {
    color: #ff0000; text-decoration: none
    }

    -->
    </style>

    </head>




    <body>
    <table width="240" border="0" align="left" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF">
    <tr>
    <td >
    <%
    set rs=server.CreateObject("adodb.recordset")
    rs.open "select * from shop_anclass order by anclassidorder",conn,1,1
    if rs.recordcount=0 then
    response.write "<br>目前没有商品分类"
    else
    while not rs.eof
    %>
    <table height="0" border="0" cellpadding="0" cellspacing="0">
    <tr>
    <td colspan="2"><span class="style1"><div align="left">&nbsp;<a href="class.asp?lx=big&anid=<%=rs("anclassid")%>" target="_blank"><u><%=rs("anclass")%></u></a></div></span></td>
    </tr>
    </table>

    <table border="0" cellpadding="0" cellspacing="0">
    <%
    set rs_s=server.CreateObject("adodb.recordset")
    rs_s.open "select * from shop_nclass where anclassid="&rs("anclassid")&" order by nclassidorder",conn,1,1
    if rs_s.recordcount=0 then
    %>
    <tr>
    <td colspan="8" width="240">
    <table border="0" cellpadding="2" cellspacing="2">
    <tr>
    <td align="center" colspan="7">暂无小分类</td>
    </tr>
    <%
    else
    i=0
    while not rs_s.eof
    %>
    <tr>
    <td width="33%"> <span class="style4">&nbsp;<a href="class.asp?lx=small&anid=<%=rs("anclassid")%>&nid=<%=rs_s("nclassid")%>" target="_blank"><u><%=rs_s("nclass")%></u></a>
    <%rs_s.movenext
    if rs_s.eof then
    response.write " "
    else
    %>
    </span></td>
    <td width="33%"> <span class="style4"><a href="class.asp?lx=small&anid=<%=rs("anclassid")%>&nid=<%=rs_s("nclassid")%>" target="_blank"><u><%=rs_s("nclass")%></u></a>

    <%rs_s.movenext
    if rs_s.eof then
    response.write " "
    else
    %>
    </span></td>
    <td width="33%" height="20"> <a href="class.asp?lx=small&anid=<%=rs("anclassid")%>&nid=<%=rs_s("nclassid")%>" class="style4" target="_blank"><u><%=rs_s("nclass")%></u></a> </td>
    <%
    rs_s.movenext
    end if
    end if
    wend
    end if
    %>
    </tr>
    </table>




    <%
    rs_s.close
    set rs_s=nothing
    rs.movenext
    wend
    end if
    rs.close
    set rs=nothing
    %>
    </body>
    </html>
     
  2. 小叶

    小叶 New Member

    注册:
    2005-09-04
    帖子:
    17,941
    赞:
    33
    用div重构吧,,就不用管,几行几列的东东..
     
  3. streamlet

    streamlet New Member

    注册:
    2005-10-13
    帖子:
    11
    赞:
    0
    怎么用呀?

    楼上的我不明白呀!!具体点好吗?我是菜鸟
     
  4. 不学无术

    不学无术 Ulysses 的元神

    注册:
    2005-08-31
    帖子:
    16,714
    赞:
    39
    代码较多,我给你一个思路,你尝试自己修改一下。

    代码:
    <%
    Dim rs, sql, i
    i = 0    '这个作为一个计数器,用来控制列
    Set rs = Server.CreateObject("ADODB.Recordset")
    sql = "SELECT ID, Title FROM myTable;"
    rs.Open sql, conn, 1, 1, 1
    If rs.RecordCount > 0 Then
        Response.Write("<table width=""100%"">")
    
        Do While Not rs.EOF
            If i Mod 2 = 0 Then    '如果被2整除,就是第一列
                Response.Write("<tr><td>...</td>")    '输出行的开始 tr 和第一个单元格 td
            Else    '否则就是第二列
                Response.Write("<td>......</td></tr>")    '输出第二个单元格 td 和行的结束 tr
            End If
    
            i = i + 1    '计数器加一
            rs.MoveNext
        Loop
    
        If i Mod 2 = 1 Then Response.Write("<td>&nbsp;</td></tr>")    '如果最后一行只显示了一列,则补上一个空白单元格和 tr 的结束符
    
        Response.Write("</table>")
    End If
    %>
     
    #4 不学无术, 2005-10-13
    最后编辑: 2005-10-13
  5. 老林

    老林 New Member

    注册:
    2005-09-06
    帖子:
    10,580
    赞:
    36
    <!--#include file="conn.asp"-->
    <!--#include file="webconfig.asp"-->
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <title>无标题文档</title>
    <style type="text/css">
    <!--
    .style1 { color: #000000;
    font-size: 14px;
    font-weight: bold;
    }
    .style4 { color: #000000;
    font-size: 12px;}

    td{ LINE-HEIGHT: 130%; }

    a:link {
    color: #333333; text-decoration:none
    }
    a:visited {
    color: #333333; text-decoration: none
    }
    a:hover {
    color: #ff0000; text-decoration: none
    }

    -->
    </style>

    </head>




    <body>
    <%
    set rs=server.CreateObject("adodb.recordset")
    rs.open "select * from shop_anclass order by anclassidorder",conn,1,1
    if rs.recordcount=0 then
    response.write "<br>目前没有商品分类"
    else
    while not rs.eof
    %>
    <table height="0" border="0" cellpadding="0" cellspacing="0">
    <tr>
    <td colspan="2"><span class="style1"><div align="left">&nbsp;<a href="class.asp?lx=big&anid=<%=rs("anclassid")%>" target="_blank"><u><%=rs("anclass")%></u></a></div></span></td>
    </tr>
    </table>

    <table height="0" border="0" cellpadding="0" cellspacing="0">
    <tr>
    <%
    set rs_s=server.CreateObject("adodb.recordset")
    rs_s.open "select * from shop_nclass where anclassid="&rs("anclassid")&" order by nclassidorder",conn,1,1
    if rs_s.recordcount=0 then
    %>
    <td align="center" colspan="7">暂无小分类</td>
    <%
    else
    wm_chief_MJJ=0
    while not rs_s.eof
    if (wm_chief_MJJ mod 3)=0 then
    Response.Write("</tr><tr>")
    end if
    %>
    <td>
    &nbsp;<a href="class.asp?lx=small&anid=<%=rs("anclassid")%>&nid=<%=rs_s("nclassid")%>" target="_blank"><u><%=rs_s("nclass")%></u></a>
    </td>
    <%
    wm_chief_MJJ = wm_chief_MJJ + 1
    rs_s.movenext
    wend
    end if
    %>
    </tr>
    </table>

    <%
    rs_s.close
    set rs_s=nothing
    rs.movenext
    wend
    end if
    rs.close
    set rs=nothing
    %>
    </body>
    </html>


    不知道是不是要这样的效果
     
  6. 小叶

    小叶 New Member

    注册:
    2005-09-04
    帖子:
    17,941
    赞:
    33
    eeee
    楼上的几位好牛X..
     
  7. streamlet

    streamlet New Member

    注册:
    2005-10-13
    帖子:
    11
    赞:
    0
    真的很感谢大家