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
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
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%"> </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 %>✔ <%else%> <%end if%> <%if rs("war_kill25n") = "No" then %>✖ <%else%> <%end if%></center></td> <td class="content-list2" width="12%"><center><%if rs("war_kill25h") = "Yes" then %>✔ <%else%> <%end if%> <%if rs("war_kill25h") = "No" then %>✖ <%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 %>✔ <%else%> <%end if%> <%if rs("war_kill10n") = "No" then %>✖ <%else%> <%end if%></center></td> <td class="content-list2" width="12%"><center><%if rs("war_kill10h") = "Yes" then %>✔ <%else%> <%end if%> <%if rs("war_kill10h") = "No" then %>✖ <%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
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"
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
heh didn't realise you could put 2 variables in the order by section, all working as intended. thanks for the help