I was answering a fellow CFer on a mailing list called CF-Talk and he was asking how to eliminate the extra commas you get if you have multiple columns from a query that you just need to output as a list (ex. “joe, billy, kyle”). If you do this (look below) you will get extra commas if a column is blank.
<cfoutput query="yourQuery">
<p>#friendname1#, #friendname2#, #friendname3#, #friendname4#, #friendname5#</p>
</cfoutput>
Your output would be:
john, , william, samuel,
I use this technique to avoid this issue. Loop over a list and you woun’t run into this.
<cfoutput>
<cfset Practice = "john,jane,clyde,bobo,sammy,beth">
<p><cfloop index="i" from="1" to="#listlen(Practice)#"><cfif i GT 1>, </cfif>#listgetat(Practice,i)#</cfloop></p>
<cfset Practice = "john,,clyde,,sammy,">
<p><cfloop index="i" from="1" to="#listlen(Practice)#"><cfif i GT 1>, </cfif>#listgetat(Practice,i)#</cfloop></p>
</cfoutput>
Published under: Cold FusionLeave a message or two








