Michael, I suppose if that works for you, great. :-) But I see a few things
I would question, which might improve the look of the code (not the result:
again, I realize that what you have may provide the same result which you
want).
First, I'd just note that you really ought to define the function either at
the top or bottom of the page, rather than inside the loop. :-) And that
could be about more than just style: I'd think CF is really executing that
code and recreating the function each iteration. Since there's no "state" in
it, it doesn't cause a problem, but it just is better to move it down out of
the loop.
Second, and more important of the discussion of CFOUTPUT GROUP, it's not
really needed here, at least how you've coded things. It's really not doing
any GROUPing at all.
The reason things "work" (despite that) is that you are doing the select
distinct in the first query, which gives you the list of distinct dest
values. Since you're doing that, you don't even really get any benefit from
the GROUP in your cfoutput loop on that. There is never more than one value
of dest.
Instead, the purpose is when the result has lots of records, many of which
have the same value you want to "break" on (your dest), and you have CF do
the dirty work. The key is that you not only get all the records in one
query, but then you do an ORDER BY in that query to get them in order by
that value, and thean have CF "break" on that value.
So for your code, I'd think this would do it:
<cfquery name="top10" datasource="xxxxx" >
SELECT dest, property, url_e, price, description
FROM tableb
WHERE top10 = "1" AND description > ' '
ORDER BY dest
</cfquery>
<cfoutput query="top10" group="dest">
<b>#top10.dest#</b><br>
<table>
<cfoutput>
<tr><td >#CapFirst(str)#</td><td>#UCASE(top10.Description)#</td>
<td>$#top10.price#.00</td><td><a href="#top10.url_e#"
target="_blank">More</a></td></tr>
</cfoutput>
</table>
</cfoutput>
</cfloop>
(then include the function definition after this).
Note that I removed the first query entirely, and in the second I removed
the WHERE and added an ORDER BY.
Now, you brought up the3 desire to have only 5 records at most in the
resulting list (per dest value), and that's where I proposed adding the code
(in my earlier email). So you'd add 3 lines to the above, within the table,
as in:
<table>
<cfset ct=0>
<cfoutput>
<cfif ct++ lt 3>
<tr><td >#CapFirst(str)#</td><td>#UCASE(top10.Description)#</td>
<td>$#top10.price#.00</td><td><a href="#top10.url_e#"
target="_blank">More</a></td></tr>
</cfif>
</cfoutput>
</table>
Let me know if that does it for you, and if it then makes better sense.
Finally, why was all that within a <head> tag in your code below? :-)
Hope that helps.
/charlie
From: [email protected] [mailto:[email protected]] On Behalf Of Michael Brown
Sent: Tuesday, July 24, 2012 11:38 AM
To: [email protected]
Subject: Re: [ACFUG Discuss] Have a question about group limits
Charlie,
Tried the code on cflib.org. It did the case that I desired, but it also
caused the content in the displayed field (property) to duplicate, showing
same value for all records. See code and link below.
link: http://hotdeals.com/datatesting2.cfm
<head>
<cfquery name="groups" datasource="xxxx" >
SELECT DISTINCT dest
FROM tableb
WHERE top10 = "1" AND description = ' ';
</cfquery>
<cfloop query="groups">
<cfquery name="top10" datasource="xxxxx" >
SELECT dest, property, url_e, price, description
FROM tableb
WHERE top10 = "1" AND description > ' '
AND dest = <cfqueryparam maxlength="20" value="#groups.dest#">
LIMIT 5
</cfquery>
<!--- Either print here, or combine in one large query, using QueryNew()
outside the loop and QueryAddRow() for each result --->
<cffunction name="CapFirst" returntype="string" output="false">
<cfargument name="str" type="string" required="true" />
<cfset var newstr = "" />
<cfset var word = "" />
<cfset var separator = "" />
<cfloop index="word" list="#arguments.str#" delimiters=" ">
<cfset newstr = newstr & separator & UCase(left(word,1)) />
<cfif len(word) gt 1>
<cfset newstr = newstr & right(word,len(word)-1) />
</cfif>
<cfset separator = " " />
</cfloop>
<cfreturn newstr />
</cffunction>
<CFSET str="#top10.property#">
<cfoutput query="top10" group="dest">
<b>#top10.dest#</b><br>
<table>
<cfoutput><tr>
<td >#CapFirst(str)#</td><td>#UCASE(top10.Description)#</td>
<td>$#top10.price#.00</td><td><a href="#top10.url_e#"
target="_blank">More</a></td>
</tr></cfoutput>
</table> </cfoutput>
</cfloop>
</head>
-------------------------------------------------------------
To unsubscribe from this list, manage your profile @
http://www.acfug.org?fa=login.edituserform
For more info, see http://www.acfug.org/mailinglists
Archive @ http://www.mail-archive.com/discussion%40acfug.org/
List hosted by http://www.fusionlink.com
-------------------------------------------------------------