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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

GROUPING? a query

Status
Not open for further replies.

rmz8

Programmer
Aug 24, 2000
210
US
This not really a complex problem, but I just need to exhibit a few things before you can know what I need to do. Right now I have a template that looks like this:

+++++++++++++++++++++++++++++

<!--Check for password in URL -->
<cfif IsDefined(&quot;Password&quot;)>
<!--Authorization check -->
<cfif isDefined(&quot;Session.Auth&quot;) is NOT TRUE>
<cflocation url=&quot;login.cfm&quot;>
<cfelse>
<!--Run query to get user information -->
<cfquery datasource=&quot;LHS&quot; name=&quot;getUser&quot;>
SELECT * FROM Users WHERE (UserName = '#URL.UserName#' AND Password = '#URL.Password#')
</cfquery>
<!--Run query to get user's classes -->
<cfoutput>
<cfquery datasource=&quot;LHS&quot; name=&quot;getClasses&quot;>
SELECT Assignments.ID AS AssignmentID,* FROM Assignments,Classes WHERE (#getUser.ID# = Classes.Teacher) AND (Assignments.Class = Classes.ID)
</cfquery>
</cfoutput> I am <cfoutput query=&quot;getUser&quot;>#RealName#</cfoutput>
and here are my current assignments. Click any class to add an assignment to it.<cfoutput query=&quot;getClasses&quot;>
<ul>
<li><b><a href=&quot;assignment.cfm?Class=#getClasses.ID#&amp;Teacher=#getUser.ID#&amp;UserName=#URL.UserName#&amp;Password=#URL.Password#&quot;>#ClassName#</a></b><i>
#getClasses.AssignmentTitle#</i>
<a href=&quot;assignment.cfm?Class=#getClasses.ID#&amp;Teacher=#getUser.ID#&amp;AssignmentID=#getClasses.AssignmentID#&amp;UserName=#URL.UserName#&amp;Password=#URL.Password#&quot;>Edit</a></li>
</ul>
</cfoutput>
</cfif>
<cfelse>
<cflocation url=&quot;login.cfm&quot;>
</cfif>

+++++++++++++++++++++++++++++

This generates something like this:

+++++++++++++++++++++++++++++

I am Mr. Bernhardt and here are my current assignments. Click any class to add an assignment to it.

Computer Applications 1 Essay on ColdFusion
Computer Applications 2 Welcome!
Computer Applications 3 Welcome!
Computer Applications 1 as
Computer Applications 1 test
Computer Applications 1 09-09-99
Computer Applications 1 09-09-8898

+++++++++++++++++++++++++++++

Essentially, this lists every assignment and the class that it was made under. However, I would like to know how to have it list each assignment under the headings of each class name, for example, it would look like this:

+++++++++++++++++++++++++++++

I am Mr. Bernhardt and here are my current assignments. Click any class to add an assignment to it.

Computer Applications 1
[ul][li]Essay on ColdFusion Edit[/li]
[li]as[/li]
[li]test[/li]
[li]09-09-99[/li]
[li]09-09-8898[/li][/ul]

Computer Applications 2
Etc....

+++++++++++++++++++++++++++++

I tried using GROUP in my CFOUTPUT tag, but it didn't work. Does any one know how to help me? Thanks in advance!

Ryan ;-]
 
You'll need to add a &quot;sort by&quot; clause to your query and then use the &quot;group&quot; attribute in your <cfouput> loop.

I believe this is close to what you'll need..

<cfquery datasource=&quot;LHS&quot; name=&quot;getClasses&quot;>
SELECT Assignments.ID AS AssignmentID,* FROM Assignments,Classes
WHERE (#getUser.ID# = Classes.Teacher)
AND (Assignments.Class = Classes.ID)

order by Classes.classname asc

</cfquery>

<cfoutput query=&quot;getClasses&quot; group=&quot;classname&quot;>
#classname#
<ul>
<cfoutput>
<li>#AssignmentTitle#
</cfoutput>
</ul>
</cfoutput>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top