...

View Full Version : Grouping Recordsets



npala2001
09-12-2005, 02:29 PM
I have been looking all over the web for help on grouping recordsets within an HTML table using ASP. I am wanting to group the entrytitles by the category

EXAMPLE--

Category
- entrytitle
- entrytitle
- entrytitle

Category
- entrytitle
- entrytitle

--END EXAMPLE


Below is what I have so far:
[CODE]
Set rsUserEntries = Server.CreateObject("ADODB.Recordset")
strSQL = "SELECT [entrytitle], [category] FROM entrydata"
rsUserEntries.Open strSQL, adoCon

do until rsUserEntries.eof
response.write "<tr><td class=""UserDetailsBOLD"">"
response.write rsUserEntries("category") & "</td>"
response.write "</tr>"
response.write "<td class=""UserDetails"">"
response.write "- " & rsUserEntries("entrytitle") & "</td>"
response.write "</tr>"
rsUserEntries.movenext
loop
response.write "</table>"
rsUserEntries.close
Conn.close
set Conn=nothing

nikkiH
09-12-2005, 03:34 PM
If you want to group by, why not just, well, group by?

strSQL = "SELECT [entrytitle], [category] FROM entrydata " &_
"group by [category] order by [category], [entrytitle] "

npala2001
09-12-2005, 06:33 PM
Once I have grouped by within the select statement. Do I need to do a response.write where I want the grouped data inserted? :confused:

nikkiH
09-12-2005, 06:44 PM
It's a select statement like any other and returns rows just like others.
Difference is, the server groups and sorts them first.
So, just output the rows in a loop as you always do.

If that doesn't yield the results you wanted, we need to clarify what you meant by "grouped".

Bullschmidt
09-14-2005, 04:48 AM
And perhaps this may hopefully give you some ideas:

Classic ASP Design Tips - Grouping Data
http://www.bullschmidt.com/devtip-groupdata.asp



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum