New to CF, not sure best output approach, missing something
I searched on the forum to look for something that might answer this but didn't find much so here goes.
So far so good, but I am not sure how to fix my problem here is the background. I have two queries (stored procedures) that I use to display output. For the sake of clarity I am going to stay away from SQL techniques like union joining or re-writing my base query. The 2 results have what I need, it's just a question of how I combine them in a way that works, because my results aren't working. All db connections and results return fine, so just assume that.
Ok, so first I have a query that when dumped looks like the following, it's a count list total of items for certain people, each person has a unique ID associated with them: so a simple cfoutput query makes the result look like this:
First query result (q1)
ID Name Count1 Count2 Count3
1 Tom Luck 2 88 33
2 Sally Blue 9 7 2
3 John Code 3 3 21
4 Sam Smith 8 8 1
etc...
The first result has about 10 names.
Now what I have is a second query that is exactly the same except the numbers are different, they are current counts of those items for the people. They can be any number, but wont be larger than the total of the original. Also some Names will not appear in the list because the user has no counts so the list might look something like this
Second query result (q2)
ID Name Count1 Count2 Count3
1 Tom Luck 2 33 3
2 Sally Blue 9 4 0
4 Sam Smith 8 3 1
etc...
So it's pretty simple to just make a <cfoutput query> tag and dump one of these table out. the problem is I am trying to combine them.
The first query is the base for my output, because it will always contain more names. What I am trying to do cosmeticaly is produce the following output in coldfusion. Here is the example based on the sample data above of what it would look like:
(expected output to achieve)
ID Name Count1 Count2 Count3
1 Tom Luck 2/2 33/88 33/33
2 Sally Blue 9/9 4/7 0/2
3 John Code 0/3 0/3 0/21
4 Sam Smith 8/8 3/8 1/1
For a note the IDs don't have to be shown, but that's not an issue. So now you get the idea... now the code problem...
The cf code I wrote to do this looks like the following, but does not produce the right output.. It's close though, but I am doing something wrong.
<table style="border-style: solid; border-width: thin; font-family: Arial, Helvetica, sans-serif">
<tr><td align="center"><b>Name</b></td><td><b>count1</b></td><td><b>count2</b></td><td><b>count3</b></td></tr>
<cfoutput query="q1">
<tr><td>#q1.PersName#</td><td style="border-style: solid; border-width: thin; " align="center" >
<cfloop query="q2" >
<cfif q2.ID eq q1.ID>
<cfoutput>#q2.C1#</cfoutput>
<cfbreak> <!--- Write option and break out of loop --->
<cfelse>
0
</cfif>
</cfloop>
/ #q1.C1#</td>
<td style="border-style: solid; border-width: thin; " align="center" >/ #q1.C2#</td>
<td style="border-style: solid; border-width: thin; " align="center" >/ #q1.C3#</td></tr>
</cfoutput>
</table>
I am getting a bit of redundancy because it's obviously going through the second query for each record instance of the first one producing the same count number over and over again for count1. (for the sake of simplicity I did not re do this code for counts2 and 3 because I can't get this working correctly).
I am not sure how to code this, but I am sure the fix is real simple either by a property designation or some other way.
Any advice would be appreciated to get the right output expected above.
thanks,
