Web Analytics Made Easy -
StatCounter displaying results in table by group - CodingForum

Announcement

Collapse
No announcement yet.

displaying results in table by group

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • displaying results in table by group

    I am looking to display a series of names (whose fields have been concatenated) grouped by room assignment, for example. And I can get one table to display, but I need to get a table for each room assignment. Hope that makes sense.

    An example of what I would want one of my tables to look like is:

    ------------------------
    | E 1 <- Table 1 Header
    ------------------------
    | Smith, John A. <- Table 1 Names
    ------------------------
    | Doe, Bob D. <- "
    ------------------------
    | Roberts, Jeff P. <- "
    ------------------------

    ------------------------
    | E 2 <- Table 2 Header
    ------------------------
    | Doe, Jane <- Table 2 Names
    ------------------------
    | Simms, Harriet <- "
    ------------------------
    | Winters, Kris P. <- "
    ------------------------

    Currently, I have been able to display all fields from a recordset in a table using the following code.

    <table border=1 cellpadding="1" cellspacing="2" cols=<%=rsSignup.fields.Count%>>
    <tr>
    <% dim objField
    For Each objField in rsSignup.fields %>
    <TH> <%=objField.name %> </TH>
    <% Next %>
    </tr>
    <% Do while Not rsSignup.EOF %>
    <tr>
    <% For each objField in rsSignup.Fields %>
    <TD align=right>
    <% if IsNull(objField) Then
    Response.Write("&nbsp;")
    else
    Response.Write(objField.Value)
    End if
    %>
    </TD>
    <% Next
    rsSignup.MoveNext %>
    </tr>
    <% Loop %>
    </Table>

    I feel like I am really close to getting it all grouped...but I need some direction!

    Help?

  • #2
    I'm not 100% sure I understand what you mean, but I think what you need to do is:
    1) Use "order by" in the sql statement that populates the recordset so that the records are sorted by room assignment.
    2) Have a variable in your script that holds the current room.
    3) When you are moving through the records, compare the value of the variable with the value of the room assignment field from the next record, and if it's different start a new table and update the variable:
    Code:
    do while not rsSignup.EOF
      ' put the table opening code here
      currentRoom = rsSignup("room_assignment")
      do while rsSignup("room_assignment") = currentRoom and not rsSignup.EOF
        ' put the table filling code here
      loop
      ' put the table closing code here
    loop
    shmoove

    Comment

    Working...
    X