|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
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> |
|
#2
|
|||
|
|||
|
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 |
|
#3
|
|||
|
|||
|
Yup. That's where I kept going but it just didn't make sense for whatever reason. I need a nap...
Thanks! |
|
#4
|
|||
|
|||
|
The Nap is the answer to all of man's greatest problems/mysteries. When all else fails...take a nap
|
|
#5
|
|||
|
|||
|
Agreed.
Nap. |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > ColdFusion Development > Outputting data in parent/child relationship |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|