Eliminating last comma in my dynamic output
Eliminating last comma in my dynamic output
(OP)
My current output of dynamic names in my variable (called dynNames) has a comma at the end.
I need to eliminate the last comma:
Jones, Smith, Baker, Johnson,
to look like this:
Jones, Smith, Baker, Johnson
My attempt to eliminate the last comma doesnt work because it eliminates all the commas:
Output from my bad attempt:
Jones Smith Baker Johnson
Please advise.
I need to eliminate the last comma:
Jones, Smith, Baker, Johnson,
to look like this:
Jones, Smith, Baker, Johnson
My attempt to eliminate the last comma doesnt work because it eliminates all the commas:
CODE
<cfset myNames = REReplace(dynNames, ",$" "", "All")>
<cfoutput>#myNames</cfoutput>
<cfoutput>#myNames</cfoutput>
Output from my bad attempt:
Jones Smith Baker Johnson
Please advise.
RE: Eliminating last comma in my dynamic output
<cfset myNames = REReplace(dynNames, ",$", "")>
This was my test:
CODE
<cfset myNames = REReplace(one, ",$", "")>
<cfoutput>
#one#<br>
#myNames#
</cfoutput>
The display comes as you want.
____________________________________
Just Imagine.
http://www.imajinarts.com
RE: Eliminating last comma in my dynamic output
It still gets rid of all my commas because
it actually outputs from a nested output.
I have the names output that shows like this from the database:
Jones Carson Richards
But I put in a comma to show better. The problem is I dont want the comma to show after the last name.
CODE
#id#<br>
<cfoutput>
<cfset dynNames = "#names#,">
<cfset myNames = REReplace(dynNames, ",$", "")>
#myNames#
</cfoutput>
<cfoutput>
RE: Eliminating last comma in my dynamic output
<cfset myNames = ValueList(otherquery.dynNames)>
www.jetansolutions.com
RE: Eliminating last comma in my dynamic output
I think my problem is this is in a nested cfoutput.
I am taking the data which is in variable names that looks like this as an output:
Jones Rivers Baker Johnson
and putting comma delimeters on them like this:
CODE
Jones, Rivers, Baker, Johnson,
I tried all suggestions in this thread and all of them knock off all the commas but I only need the last comma knocked off. I assume I have an output issue.
Should I do this another way? If so please advise.
RE: Eliminating last comma in my dynamic output
<cfset dynNames = '>
<cfloop ...> OR <cfoutput query="..">
<cfset dynNames = dynNames&','&#names#>
</cfloop> / </cfoutput>
hope it helps...
www.jetansolutions.com
RE: Eliminating last comma in my dynamic output
CODE
<cfoutput query="..">
<cfset dynNames = dynNames&','&#names#>
</cfoutput>
It outputs:
,Jones, Rogers, Baker
How do I get rid of first comma?
RE: Eliminating last comma in my dynamic output
<cfset dynNames = '>
<cfoutput query="..">
<cfif ListLen(dynNames) EQ 0>
<cfset dynNames = dynNames&#names#>
<Cfelse>
<cfset dynNames = dynNames&','&#names#>
</cfif>
</cfoutput>
www.jetansolutions.com
RE: Eliminating last comma in my dynamic output
It must be something for how I have my nested output which I need.
CODE
#id#<br>
<cfoutput>
<cfset dynNames = ''>
<cfif ListLen(dynNames) EQ 0>
<cfset dynNames = dynNames&#names#>
<Cfelse>
<cfset dynNames = dynNames&','&#names#>
</cfif>
</cfoutput>
<cfoutput>
RE: Eliminating last comma in my dynamic output
r937.com | rudy.ca
RE: Eliminating last comma in my dynamic output
CODE
#id#<br>
<cfoutput>
<cfset dynNames = ValueList(otherquery.names)>
#dynNames#
</cfoutput>
</cfoutput>
RE: Eliminating last comma in my dynamic output
do this instead --
<cfset dynNames = ValueList(otherquery.names)>
<cfoutput>
#dynNames#
</cfoutput>
r937.com | rudy.ca
RE: Eliminating last comma in my dynamic output
CODE
<cfoutput query="otherquery" group="id">
#id#<br>
<cfset dynNames = ValueList(otherquery.names)>
<cfoutput>
#dynNames#
</cfoutput>
</cfoutput>
RE: Eliminating last comma in my dynamic output
what do you get when you run this --
CODE
select names from ...
</cfquery>
<cfset dynNames = ValueList(otherquery.names)>
<cfoutput>
#dynNames#
</cfoutput>
r937.com | rudy.ca
RE: Eliminating last comma in my dynamic output
No I dont have comma delimited names in the names column.
I appreciate all the input and I assume I will have to make my output with just spaces in between the names to solve my problem?
CODE
#id#<br>
<cfoutput>
<cfset dynNames = "#names# ">
#dynNames#
</cfoutput>
</cfoutput>
RE: Eliminating last comma in my dynamic output
r937.com | rudy.ca
RE: Eliminating last comma in my dynamic output
<cfoutput query="otherquery" group="id">
#id#<br>
<!--- this used to be reseting to ' after every name, it was in the loop of the nested cfoutput
<cfset dynNames = '>
<cfoutput>
<cfif ListLen(dynNames) EQ 0>
<!--- we know cynNames is ', so no reason for dynNames&names --->
<cfset dynNames = names>
<cfelse>
<!--- working with a list, use a list function --->
<cfset dynNames = listAppend(dynNames,names)>
</cfif>
</cfoutput>
<cfoutput>
valuelist() won't work because of the CFOUTPUT with group... he wants a list of names PER id. valuelist give the ENTIRE list of names to EVERY id.
Kevin
http://www.lot-o-nothin.com/cfml/
Phase 1: Read the CFML Reference
Phase 2: ???
Phase 3: Profit!
RE: Eliminating last comma in my dynamic output
r937.com | rudy.ca
RE: Eliminating last comma in my dynamic output
Kevin
http://www.lot-o-nothin.com/cfml/
Phase 1: Read the CFML Reference
Phase 2: ???
Phase 3: Profit!
RE: Eliminating last comma in my dynamic output
yeah, it's been a rough month for me
old computer died, had to get a new one
had to upgrade myself on all sorts of software
on the plus side, i was finally able to install cf on my own machine, and actually hook it up to a local mysql database so that i can test cf queries...
(i had never succeeded in installing cf in 8 years of using it -- i had always just uploaded my .cfm files to my host)
also, being forced to set up a new machine for my own development purposes inevitably meant that i had to find some new software to replace things i had been using that you can't get anymore, such as the free version of mysql-front, which i very joyfully was able to replace with Heidi SQL (a spinoff of mysql-front) -- if you haven't tried it, it's way better than phpmyadmin)
r937.com | rudy.ca
RE: Eliminating last comma in my dynamic output
This is what finally worked.
I am not sure what ListAppend() function does?
I assume it adds each record find to a list?
CODE
#id#<br>
<cfset dynNames = "">
<cfoutput>
<cfset dynNames = listappend(dynnames,names)>
</cfoutput>
#dynNames#
</cfoutput>
RE: Eliminating last comma in my dynamic output
Here is what worked:
CODE
#id#<br>
<cfoutput>
<cfset dynNames = "">
<cfset dynNames = listappend(dynnames,names)>
</cfoutput>
#dynNames#
</cfoutput>