I have an object oriented database, the database has two objects,
PERSON_TYPE_DESC (a persons type) and NAME (the person) theses are called
and joined by a view called people.  I have simplified the code as I use
tags as methods, so the example/question is easier to demonstrate.

Here is the issue, if a person type has more than one person attached I want
I want there to be an (s) after the person type and no (s) if the person
type only has one person.  Also, I do not want there to be a comma after the
last person associated in the display.

So if you simply use cfouput and its group attribute...

<cfoutput query="people" group="PERSON_TYPE_DESC">
    #PERSON_TYPE_DESC#s:
    <cfoutput>
     #NAME#,
      </cfoutput>
       <br>
</cfoutput>
you might get something like this:

Producers: Sean Renet,
Song Writers: Dave Watts, Steve Nelson,

I guess an alternate would be to not use commas at all and use (s) like so

Producer(s): Sean Renet
Song Writer(s): Dave Watts Steve Nelson

I think that looks just as lame so I came up with the following code using
lists.  It works fine, I am just wondering if anyone has anything slicker.
Oh and yes I intend to tagify this, this is just first blush.

<cfparam name="persontypelist" default="">
<cfparam name="personlist" default="">
<cfparam name="fullpersonlist" default="">

<!--- output people query to set up lists grouping on PERSON_TYPE_DESC--->
<cfoutput query="people" group="PERSON_TYPE_DESC">
<!--- set the person type list separated by a | as this is the top level
list --->
     <cfset persontypelist =
listappend(persontypelist,PERSON_TYPE_DESC,"|")>
     <cfoutput>
  <!--- add a space to the name so there will be a space between multiple
names  --->
          <cfset thisperson = "&nbsp;" & name>
  <!--- make a sublevel list with a comma grouping it at the top level
list --->
          <cfset personlist = listappend(personlist,thisperson,",")>
     </cfoutput>
 <!--- make a person list that reconciles sublevel list with top level list
position --->
     <cfset fullpersonlist = listappend(fullpersonlist,personlist,"|")>
 <!--- clear sublevel list --->
     <cfset personlist = "">
</cfoutput>

<!--- set a loop based on the length of top level list --->
<cfloop index="i" from="1" to="#listlen(persontypelist,"|")#">
<!--- output data using loop index as position for top level lists and check
the length of reconciled sublevel list to decide whether to add an (s) to
top level person type output --->
     <cfoutput>
         #listgetat(persontypelist,i,"|")#<cfif
listlen(listgetat(fullpersonlist,i,"|"),",") GT
1>s</cfif>:&nbsp;&nbsp;#listgetat(fullpersonlist,i,"|")# <br>
     </cfoutput>
</cfloop>

this produces...

Producer: Sean Renet
Song Writers: Dave Watts, Steve Nelson

wouldn't be great if there was a query_name.group.RecordCount variable?
I will eventually use CFASSOCIATE to tagify this, but I just wanted to
easily explain what I was trying to do.

------------------------------------------------------------------------------------------------
Archives: http://www.mail-archive.com/cf-talk@houseoffusion.com/
Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists or send a message 
with 'unsubscribe' in the body to [EMAIL PROTECTED]

Reply via email to