Getting data within a CFLOOP

Good Morning!! I was hoping to get a little help with a query, and ultimate ColdFusion output. I have data in two tables and I use a CFLOOP to display project numbers and associated data from these tables. The query is below:

<CFQUERY DATASOURCE="PDBARMYDEV" NAME="CecomInput">
SELECT current_bulk_filter.proj_no,
       current_bulk_filter.capces_location,
       current_bulk_filter.capces_state,
       current_bulk_filter.capces_description,
       capces_support_history.proj_closed_reason

FROM   mca.current_bulk_filter
 
  left join mca.capces_support_history
        on current_bulk_filter.proj_no = capces_support_history.proj_no  

        where capces_support_history.proj_closed_reason is not null      
order by current_bulk_filter.proj_no asc
       </CFQUERY>

The problem I'm having is capces_support_history table. This table could have several rows for each individual project number. What I would like is to be able to have a textarea with all of the comments for each project number in one box. Right now its only picking up the latest record. But I would like the textarea to have all of the comments listed for each project. I guess kinda like a loop within a loop?? Any help would be greatly appreciated
diecasthft01Asked:
Who is Participating?
 
gdemariaCommented:
It sounds like you want to use cfoutput group="xxx"    where xxx is the column name of the 'parent' table that will indicate when the inner loop will break.

Using the analogy of a query pulling artists and their songs (many songs to one artist), it would work this way...

<cfoutput query="getSongs" group="artistName">
     #getSongs.ArtistName#<br>
    <cfoutput>
        #getSongs.songName#<br>
    <./cfoutput>
<./cfoutput>
0
 
_agx_Commented:
Right now its only picking up the latest record.

Do you mean a dump of the raw query only contains the latest history record OR your query output only displays one record?  Can you dump the raw query to check?

<cfdump var="#CecomInput#">
0
 
_agx_Commented:
IF the query contains the proper records (multiple history records per project number), a grouped output should do what you need.  Something like this:
<cfoutput query="CecomInput" group="proj_no">
       <!--- This will print once for every project --->
       proj_no = #proj_no#<br>
       <!--- This will print each reason within a single textarea --->
     <textarea><cfoutput>#proj_closed_reason##chr(10)#</cfoutput></textarea>
     <br>
</cfoutput>

Open in new window


Note, the query MUST be ordered by the group column first, ie ORDER BY proj_no for it to work correctly.
0
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

 
_agx_Commented:
Darn, too slow!   GD already said the same thing ;-)
0
 
diecasthft01Author Commented:
The above theory is correct in that it gets me all of my records. The problem is that it creates a new line in my web output for each project number, so if I have a project number 12345, and it had three proj_closed_reason entries, then I now have three rows with that same project number. What I'd like to do is have one row for each project number, but then in a text box within that row, get all of the proj_closed_reason entries and put that output in one textarea, so my output in that textarea would be "reason1, reason 2, reason 3".
0
 
_agx_Commented:
If I'm understanding correctly, you want the query to contain three separate rows. The "grouped" cfoutput in the CFML code will then condense them into the desired format.  

Did you try GD's code or mine? They both should accomplish that. It's just a matter of tweaking the formatting.  My example should produce the output described, only with new lines instead of commas, but that is easily changed.  The current output should look like this:

12345
<textarea>
    reason1
    reason2
    reason3
</textarea>

67890
<textarea>
    ... reasons 
</textarea>

Open in new window

0
 
diecasthft01Author Commented:
Oh wait...I see the problem on my end I think. Let me reverse course here, but yeah I think that's going to do what I want it to do.
0
 
_agx_Commented:
Okay, it's basically the same thing GD already said. Just threw in a <textarea> and changed the column names.
0
 
diecasthft01Author Commented:
That should do it for me. Thank you both for your time and help with this.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.