Bullschmidt.com
Home
Web Database Concept
How We Work Together
Bio
Web Database Sample
Classic ASP Design Tips
Bar Chart Tool
Web Design Resources
Access Database Sample
Classic ASP Design Tips
Grouping Data
These are opinions of J. Paul Schmidt, MBA.
No warranties are either expressed or implied.
To Use Paul's Services:
Paul@Bullschmidt.com
Here is a way to group data so that it looks something like this:
Crafts:
Andrews, Beth
Thomas, Jean
Meals:
Johnson, Sally
Martin, Cindy
Sports:
Smith, Tom
Jones, George
Within the recordset looping compare the field you want to group on such as Category with the Category of the previous record (perhaps stored in a variable called CategoryPrev) and only if it's different then do something like show a new group header.
<%
' Set Category for this record.
Category = objRS("Category")
' Show new group header if needed.
If Category <> CategoryPrev Then
%>
<tr>
<td>
<br>
<b><%= Category %>:</b>
</td>
</tr>
<%
End If
%>
<% ' Show normal data every time. %>
<tr>
<td>
<%= LName %>, <%= FName %>
</td>
</tr>
<%
' Set CategoryPrev here to be Category for use next time thru the loop.
CategoryPrev = Category
%>
And the above assumes that things are sorted correctly in the SQL statement with perhaps something like ORDER BY Category, LName, FName.
And of course one could get even more advanced using the same concept to create multiple levels of grouping.
To Use Paul's Services:
Paul@Bullschmidt.com
Copyright © 2000-2010
J. Paul Schmidt, MBA
Freelance Web and Database Developer
All Rights Reserved
Privacy Policy