日期:2014-05-17  浏览次数:20884 次

asp横向循环的一个特殊要求
源代码如下,没有问题

        <%
Set   rs=   Server.CreateObject( "ADODB.Recordset ")
sql= "select   *   from   table "
rs.Open   sql,conn,1,1
for   x=1   to   rs.recordcount

response.write   " <a   href= " "view.asp?id= "   &   rs( "id ")   &   " " "> "&   rs( "name ")   &   " </a> "

if   x   mod   6   =0   then   response.write   " <P> "
rs.movenext
next
rs.close
set   rs=nothing
%>

========================================================================

现在希望每行的6个结果中,前三个加一个标识left,后三个加上另外一个标识reght,即:
前三个的输出语句为
response.write   " <a   im= " "left " "   href= " "daoshiok_view.asp?id= "   &   rs( "id ")   &   " " "> "&   rs( "ds_name ")   &   " </a> "
后三个的输出语句为
response.write   " <a   im= " "right " "   href= " "daoshiok_view.asp?id= "   &   rs( "id ")   &   " " "> "&   rs( "ds_name ")   &   " </a> "

这个该这么做呢?

------解决方案--------------------
<%
Set rs= Server.CreateObject( "ADODB.Recordset ")
sql= "select * from table "
rs.Open sql,conn,1,1
k=0
for x=1 to rs.recordcount
If k <3 Then
response.write " <a im= " "left " " href= " "view.asp?id= " & rs( "id ") & " " "> "& rs( "name ") & " </a> "
Else
response.write " <a im= " "right " " href= " "view.asp?id= " & rs( "id ") & " " "> "& rs( "name ") & " </a> "
End if
if x mod 6 =0 then
response.write " <P> "
k=0
Else
k=k+1
End if
rs.movenext
next
rs.close
set rs=nothing
%>