Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Grandparent, parent, child query

Status
Not open for further replies.

webmigit

Programmer
Joined
Aug 3, 2001
Messages
2,027
Location
US
Off on another tangent about this script.. here's what my goal is.. I want to use one query, if possible to get a list of schools the user has selected.

In the table schools, we have region, division, school.. I'd like to output like this:

Region 1
Division 1
School 1
School 2
School 3
Division 2
School 1
School 2
School 3
School 4
School 5
Division 3
School 1
Division 4
School 1
School 2
School 3
School 4

6 regions, 4 divisions in each region.. Can someone help me with a cfquery to stagger Region,Division,School like this??

Thanks
Tony Hicks [ Founder of <A href=&quot; online bible. ]
 
Tony,
You can use the Order By clause and use the build in groupby attribute in your cfoutput that will format this way.

e.g
<cfquery name=&quot;foo&quot; datasource=&quot;bar&quot;>
Select Region,Divsion,School from MyTable

Order by Region,Division,School
</cfquery>

<cfoutput query=&quot;foo&quot; group=&quot;Region&quot;>
#Region# <br>
<cfoutput group=&quot;Division&quot;>
--- #Division#<br>
</cfoutput>
<cfoutput group=&quot;Division&quot;>
------ #School#<br>
</cfoutput>
</cfoutput>

Notice the nesting cfoutputs with the Group.

HTH,
Tim P.
 
er -- sorry, I just realized I made a copy mistake, the last group should be

<cfoutput group=&quot;School&quot;>
------ #School#<br>
</cfoutput>

Or you can use simply:
<cfoutput>
------ #School#<br>
</cfoutput>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top