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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

_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
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
_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
Become a Certified Penetration Testing Engineer

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

_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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ColdFusion Language

From novice to tech pro — start learning today.