How to break down list into categories

Discussion in 'C#' started by Tarqy, Apr 1, 2009.

  1. #1
    Hi, Im looking for some advice on how to breakdown a list of data into categories, im new to all this and cant seem to find any guide or example script

    The code im using at the moment to display the list is below but i would like to somehow break it down into separate sections by "class"

    
    <%
    Dim main_members
    Dim main_members_numRows
    
    Set main_members = Server.CreateObject("ADODB.Recordset")
    main_members.ActiveConnection = MM_guilddb_STRING
    main_members.Source = "SELECT * FROM TEAM ORDER BY team_class ASC"
    main_members.CursorType = 0
    main_members.CursorLocation = 2
    main_members.LockType = 1
    main_members.Open()
    
    main_members_numRows = 0
    %>
    <%
    Dim Repeat7__numRows
    Dim Repeat7__index
    
    Repeat7__numRows = -1
    Repeat7__index = 0
    main_members_numRows = main_members_numRows + Repeat7__numRows
    %>
    
    <table width="100%" border="0" cellpadding="0" cellspacing="0" class="">
                                        <tr> 
                                          <td class="content-title2" width="40%"><strong>Character Name</strong></td>
                                          <td class="content-title2" width="20%"><strong>Race</strong></td>
                                          <td class="content-title2" width="20%"><strong>Class</strong></td>
                                          <td class="content-title2" width="20%"><strong>Rank</strong></td>
                                        </tr>
                                        <% Row = 0 %>
                                        <% 
    While ((Repeat7__numRows <> 0) AND (NOT main_members.EOF)) 
    %>
                                        <% if (Row = 2) Then %>
                                        <tr> 
                                          <td class="content-page" width="40%"><a href="http://eu.wowarmory.com/character-sheet.xml?r=Shadowsong&n=<%=(main_members.Fields.Item("team_alias").Value)%>" target="_blank"><%response.write(main_members.Fields.Item("team_alias").Value)%></a></td>
                                          <td class="content-page" width="20%"><%=(main_members.Fields.Item("team_race").Value)%></td>
                                          <td class="content-page" width="20%"><%=(main_members.Fields.Item("team_class").Value)%></td>
                                          <td class="content-page" width="20%"><%=(main_members.Fields.Item("team_rank").Value)%></td>
                                        </tr>
                                        <%
        	Row = 1
        		
        	Else 
        		
        		Row = 2 %>
                                        <tr> 
                                          <td class="content-page" width="40%"><a href="http://eu.wowarmory.com/character-sheet.xml?r=Shadowsong&n=<%=(main_members.Fields.Item("team_alias").Value)%>" target="_blank"><%response.write(main_members.Fields.Item("team_alias").Value)%></a></td>
                                          <td class="content-page" width="20%"><%=(main_members.Fields.Item("team_race").Value)%></td>
                                          <td class="content-page" width="20%"><%=(main_members.Fields.Item("team_class").Value)%></td>
                                          <td class="content-page" width="20%"><%=(main_members.Fields.Item("team_rank").Value)%></td>
                                        </tr>
                                        <%
        	End if
    		
    %>
                                        <% 
      Repeat7__index=Repeat7__index+1
      Repeat7__numRows=Repeat7__numRows-1
      main_members.MoveNext()
    Wend
    %>
                                      </table>
    
    
    Code (markup):
    Any suggestions or examples would be appreciated, thanks :)
     
    Tarqy, Apr 1, 2009 IP
  2. engager

    engager Peon

    Messages:
    28
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    I would do something like this.
    before while loop declare some variable and initialize in with empty string e.g. currentTeamClass = ""
    then in every iteration inside while loop compare it with team_class field value.
    if currentTeamClass <> main_members("team_class") then
    currentTeamClass = main_members("team_class")
    Response.Write "<strong>Category " & currentTeamClass & "</strong>"
    end if
     
    engager, Apr 7, 2009 IP
  3. Tarqy

    Tarqy Peon

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thanks for the help, i managed to get it to work using the following script however i have one quick questions,

    <%
    accessdb="..." 
    cn="driver={Microsoft Access Driver (*.mdb)};"
    cn=cn & "dbq=" & server.mappath(accessdb)
    
    set rs = server.createobject("ADODB.Recordset")
    
    sql = "select * from wars order by war_instance desc" 
    rs.Open sql, cn
    
    rs.movefirst
    do while not rs.eof
    
    category=rs("war_instance")
    
    if category <> last_category then 
    %>
    <br>
    <table width="100%" border="0" cellpadding="0" cellspacing="0" class="">
    <tr>
     									  <td class="content-title2" width="100%"><strong><%= category %></strong></td>
     </tr>
                                        </table>
    
    <%
    end if  
    %>
    <table width="100%" border="0" cellpadding="0" cellspacing="0" class="">
                                        <tr>
                                          <td class="content-list2" width="15%">&nbsp;</td>
                                          <td class="content-list2" width="35%"><a href="boss_more.asp?ID=<%= rs("ID") %>"><%= rs("war_boss") %></a></td>
                                          <td class="content-list2" width="13%"><center><%if rs("war_kill25n") = "Yes" then %>&#10004;
    											<%else%>
    											<%end if%>
    											<%if rs("war_kill25n") = "No" then %>&#10006;
    											<%else%>
    											<%end if%></center></td>
                                          <td class="content-list2" width="12%"><center><%if rs("war_kill25h") = "Yes" then %>&#10004;
    											<%else%>
    											<%end if%>
    											<%if rs("war_kill25h") = "No" then %>&#10006;
    											<%else%>
    											<%end if%>
    											<%if rs("war_kill25h") = "N/A" then %>N/A
    											<%end if%></center></td>
                                          <td class="content-list2" width="13%"><center><%if rs("war_kill10n") = "Yes" then %>&#10004;
    											<%else%>
    											<%end if%>
    											<%if rs("war_kill10n") = "No" then %>&#10006;
    											<%else%>
    											<%end if%></center></td>
                                          <td class="content-list2" width="12%"><center><%if rs("war_kill10h") = "Yes" then %>&#10004;
    											<%else%>
    											<%end if%>
    											<%if rs("war_kill10h") = "No" then %>&#10006;
    											<%else%>
    											<%end if%>
    											<%if rs("war_kill10h") = "N/A" then %>N/A
    											<%end if%></center></td>                                  
                                        </tr>
                                         </table>
                                                                              <%
     
    last_category=category
    rs.MoveNext
    loop
    %>
    
    Code (markup):
    I need to know how to arrange the data from each category by id descending if thats possible? at the moment the output seems to be completely random
     
    Tarqy, Apr 12, 2009 IP
  4. camjohnson95

    camjohnson95 Active Member

    Messages:
    737
    Likes Received:
    17
    Best Answers:
    0
    Trophy Points:
    60
    #4
    change sql from
    sql = "select * from wars order by war_instance desc"
    to:
    sql = "select * from wars order by war_instance desc, cat_id desc"
     
    camjohnson95, Apr 13, 2009 IP
  5. camjohnson95

    camjohnson95 Active Member

    Messages:
    737
    Likes Received:
    17
    Best Answers:
    0
    Trophy Points:
    60
    #5
    ORDER BY will sort by ascending by default, the following statement:
    select * from wars order by war_instance, cat_id desc
    will order by war_instance asc and cat_id desc... that is why it is necessary to use 'desc' for both columns
     
    camjohnson95, Apr 13, 2009 IP
  6. Tarqy

    Tarqy Peon

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    heh didn't realise you could put 2 variables in the order by section, all working as intended. thanks for the help
     
    Tarqy, Apr 13, 2009 IP