我有下表:
Name Type Color Place
Ana A Blue America
Sandra A Red India
Mary A Red America
Paige B Orange Africa
Fox B White Africa
John C Black Mexico
我想按类型和节目对itens进行分组,如下所示:
Type A
Ana - Blue - America
Sandra - Red - India
Mary - Red - America
Type B
Paige - Orange - Africa
Fox - White - Africa
Type C
John - Black - Mexico
什么样的循环可以帮助我?
谢谢!
答案 0 :(得分:1)
只需选择您的记录,按类型排序,然后循环记录集。
跟踪变量中的Type,每当Type更改时,在写出下一个Type之前添加换行符。
编辑:例如:
<%
Dim strType
do while not rs.EOF
if strType <> rs("Type") then ' <---- check if the types are different here
Response.Write "Type " & rs("Type") & "<BR><BR>"
end if
' your user records go here
strType = rs("Type") ' <---- set the strType variable before looping
rs.MoveNext
loop
%>
答案 1 :(得分:0)
select Name, Color, Place
from MyTable
order by Type
然后在ASP代码中,当Type值与之前的Type(或第一行)不同时,打印出Type头行。