Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Jul 2004
    Posts
    98
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Grouping Recordsets

    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

  • #2
    Senior Coder nikkiH's Avatar
    Join Date
    Jun 2005
    Location
    Near Chicago, IL, USA
    Posts
    1,973
    Thanks
    1
    Thanked 32 Times in 31 Posts
    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] "

    If this post contains any code, I may or may not have tested it. It's probably just example code, so no getting knickers in a bunch over a typo, OK? If it doesn't have basic error checking in it, such as object detection or checking if objects are null before using them, put that in there. I'm giving examples, not typing up your whole app for you. You run code at your own risk.
    Bored? Visit
    http://www.kaelisspace.com/

  • #3
    New Coder
    Join Date
    Jul 2004
    Posts
    98
    Thanks
    0
    Thanked 0 Times in 0 Posts

    One last dumb question

    Once I have grouped by within the select statement. Do I need to do a response.write where I want the grouped data inserted?

  • #4
    Senior Coder nikkiH's Avatar
    Join Date
    Jun 2005
    Location
    Near Chicago, IL, USA
    Posts
    1,973
    Thanks
    1
    Thanked 32 Times in 31 Posts
    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".

    If this post contains any code, I may or may not have tested it. It's probably just example code, so no getting knickers in a bunch over a typo, OK? If it doesn't have basic error checking in it, such as object detection or checking if objects are null before using them, put that in there. I'm giving examples, not typing up your whole app for you. You run code at your own risk.
    Bored? Visit
    http://www.kaelisspace.com/

  • #5
    Regular Coder
    Join Date
    Aug 2002
    Location
    USA
    Posts
    478
    Thanks
    0
    Thanked 2 Times in 2 Posts
    And perhaps this may hopefully give you some ideas:

    Classic ASP Design Tips - Grouping Data
    http://www.bullschmidt.com/devtip-groupdata.asp
    J. Paul Schmidt
    www.Bullschmidt.com - Freelance Web and Database Developer
    www.Bullschmidt.com/DevTip.asp - Classic ASP Design Tips


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •