#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Posts
    3
    Rep Power
    0

    Lightbulb Select Distinct Command


    I have a database with the following values:

    Item A, Boa, Snakes
    Item B, Boa, Snakes
    Item C, Boa, Snakes
    Item D, Python, Snakes
    Item E, Python, Snakes
    Item F, Collubrid, Snakes

    I want the output to look like this though:

    Snakes
    --> Boas
    --------> Item A
    --------> Item B
    --------> Item C
    --> Pythons
    --------> Item D
    --------> Item E
    --> Collubrid
    --------> Item F

    How do I structure this in CFML to give me this output?
  2. #2
  3. No Profile Picture
    Moderator

    Join Date
    Jun 2002
    Location
    Raleigh, NC
    Posts
    5,273
    Rep Power
    968

    Re: Select Distinct Command


    Use CFOUTPUT with the GROUP attribute:

    PHP Code:
    <cfoutput query="myQuery" group="animalType">
    #animalType#<br>
     
    <cfoutput group="animalName">
     
    #animalName#<br>
       
    <cfoutput>
       
    #itemNo#<br>
       
    </cfoutput>
     </
    cfoutput>
    </
    cfoutput
    You could also do this manually with nested loops, as you would have to do with PHP. But the group attribute makes it much easier.
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Posts
    3
    Rep Power
    0
    sorry, i needed the SQL code for this too....what's the query look like??

    <cfoutput query="myQuery" group="animalType">
    #animalType#<br>
    <cfoutput group="animalName">
    #animalName#<br>
    <cfoutput>
    #itemNo#<br>
    </cfoutput>
    </cfoutput>
    </cfoutput>
  6. #4
  7. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Posts
    3
    Rep Power
    0
    never mind, i got it!

    great work, thanks for the speedy response.

IMN logo majestic logo threadwatch logo seochat tools logo