Search code examples
asp-classic

How to number of sub items in grouped list


I am using classical asp. I have to tables. The first table that is called "sorutip" have tiles of every group. The second table that is called "Questions41" have questions. I want to number each group starting from 1 as in the example below.

Complete the gaps.

1- ...........
2- .......
3- ...........
4- ...........

Answer the questions

1- ......?
2- .......?
3- .....?
4- .....?
5- ....?
6- ......?

Put the sentences into the correct order

1- .....
2- .......
3- ....
4- ......

My code is here

    <%Set oRS= conn.Execute("SELECT  DISTINCT(questions41.tid),sorutip.tid,sorutip.title, questions41.question FROM questions41 LEFT JOIN sorutip ON questions41.tid=sorutip.tid  GROUP BY questions41.tid,sorutip.tid,sorutip.title,questions41.question") 

Dim title2, previousGroupName
title2 = ""
previousGroupName = ""


Do Until oRS.EOF
    title2 = oRS("title")
    question= oRS("question")
    If title2<>previousGroupName Then
        Response.Write("<p>")
       Response.Write(oRS("title"))
        Response.Write("</p>")
    End If
 

number=number+1

Response.Write(" "&  number &"- " & question & "<br />")
    previousGroupName = title2

    oRS.MoveNext
Loop
oRS.Close%>

Solution

  • You just need to reset the number when starting a new group

    If title2<>previousGroupName Then 
        Response.Write("<p>")
        Response.Write(oRS("title"))
        Response.Write("</p>")
        number = 0
    End If