ColdFusion Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreColdFusion Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old June 9th, 2005, 10:51 AM
Bastion Bastion is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2004
Posts: 181 Bastion User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 Days 4 h 25 m 11 sec
Reputation Power: 5
Outputting data in parent/child relationship

For whatever reason, I'm not grasping the logic I need so I'm looking for some insight.

I have a database that tracks incoming students. One table (responses) includes the student's general information and another (major) tracks the areas of study he/she is interested in learning. So I would have one record in resonses table but could have multiple records in the major table. The link is the ID--responses.ID is unique and major table includes major.majorID for each row which is really responses.ID.

Now the output is where I'm having issues. I have a left outer join running (because the student could have no major of interest).

Code:
<cfquery name="getResults" datasource="#myds#">
	SELECT	*
	FROM	responses r LEFT OUTER JOIN sai_major m ON m.majorID = r.ID
	ORDER BY	r.response_date
</cfquery>


I need to output this in an excel-style layout. Each record will have it's own row, but I want the associated majors to appear in as a list in one cell. Of course if I just do a straight query, I get 1 record output as many times as the major it's attached to.

My thought is to have <cfoutput query="getResults" group="ID"> and then loop through the list later. But is that the best/fastest way? And I need whatever speed I can get. I feel like I'm missing something obvious.

Edited to add:
I forgot to mention that there is a second child table added to the mix (my brain is so not in my head right now). So, in another area, I will have all three combined as such.

Code:
<cfquery name="getResults" datasource="#Application.myds#">
	SELECT	*
	FROM	(responses r LEFT OUTER JOIN major m ON m.majorID = r.ID) LEFT OUTER JOIN preference p ON p.prefID = r.ID
	ORDER BY	r.response_date
</cfquery>

Reply With Quote
  #2  
Old June 9th, 2005, 12:19 PM
kiteless kiteless is offline
Moderator
Dev Shed Expert (3500 - 3999 posts)
 
Join Date: Jun 2002
Location: Raleigh, NC
Posts: 3,682 kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Week 4 Days 15 h 42 m 54 sec
Reputation Power: 53
You should be able to do this using <cfoutput group="">. So you could do something like:

<tr><td>Student</td><td>Major List</td></tr>
<cfoutput group="studentID">
<tr>
<td>#studentName#</td>
<td><cfoutput>#majorName#, </cfoutput></td>
</tr>
</cfoutput>

or something similar, in that case you'd have an extra comma at the end of the cell but you can deal with that separately (build up the list as a variable, trim off the last comma, then output it, or something like that).

make sense?
__________________
Ask if you have a question, but also help answer questions that you have knowledge of! Thanks, Brian.
How to Post a Question in the Forums

Reply With Quote
  #3  
Old June 9th, 2005, 12:21 PM
Bastion Bastion is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2004
Posts: 181 Bastion User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 Days 4 h 25 m 11 sec
Reputation Power: 5
Yup. That's where I kept going but it just didn't make sense for whatever reason. I need a nap...

Thanks!

Reply With Quote
  #4  
Old June 9th, 2005, 12:36 PM
Caden Caden is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2005
Posts: 272 Caden User rank is Private First Class (20 - 50 Reputation Level)Caden User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 2 Days 7 h 8 m 8 sec
Reputation Power: 4
The Nap is the answer to all of man's greatest problems/mysteries. When all else fails...take a nap

Reply With Quote
  #5  
Old June 9th, 2005, 01:19 PM
kiteless kiteless is offline
Moderator
Dev Shed Expert (3500 - 3999 posts)
 
Join Date: Jun 2002
Location: Raleigh, NC
Posts: 3,682 kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Week 4 Days 15 h 42 m 54 sec
Reputation Power: 53
Agreed.

Nap.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreColdFusion Development > Outputting data in parent/child relationship


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway
Stay green...Green IT