2017-12-26 30 views
0

rs1という名前のレコードセットでループしています。レコードセットのループ内に列名を1回だけ表示する

 
January - 1245 
January - 5487 
January - 8547 
January - 8987 
January - 0247 
February - 7854 
February - 8541 
February - 9321 
February - 9001 
February - 6658 

結果が正しいと私がしたいことを正確ですが、あなたが見ることができるように、月のカラムは次のとおりです。私は結果を表示していた場合 は、私は、レコードの次のリストを取得しています理由なしで連続的に繰り返される。月名を表示する方法はありますか最初の行の結果は次のとおりですか?

 
January - 1245 
     - 5487 
     - 8547 
     - 8987 
     - 0247 
February - 7854 
     - 8541 
     - 9321 
     - 9001 
     - 6658 

次のように私はループをやっている方法は次のとおりです。

<% 
Dim Repeat1__numRows 
Dim Repeat1__index 

Repeat1__numRows = -1 
Repeat1__index = 0 
rs1_numRows = rs1_numRows + Repeat1__numRows 
%> 

'Here is the display of the results 

<% 
    Repeat1__index=Repeat1__index+1 
    Repeat1__numRows=Repeat1__numRows-1 
    rs1.MoveNext() 
Wend 
%> 

答えて

1

私は、DO-WHILEループを好きですが、あなたが必要とするすべてがシンプルであるとして、あなたは、あなたが好きなループを使用することができますifステートメント。

dim strMonth, numTotals 
Response.Write "<table>" 
do while not rs1.EOF 
    numTotals = rs("numTotals") 
    Response.Write "<tr>" 
    if strMonth <> rs("monthName") then 
     strMonth = rs1("monthName") 
     Response.Write "<td>" & strMonth & "</td>" 
    else 
     Response.Write "<td>&nbsp;</td>" 
    end if 

    Response.Write "<td>" & numTotals & "</td>" 
    Response.Write "</tr>" 

    rs1.MoveNext 
loop 

Response.Write "</table>" 
+0

完璧! Thk !!! – user2986570

関連する問題