Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Getting rid of the last comma in a cfoutput query 1

Status
Not open for further replies.

3dColor

Programmer
Jan 10, 2006
240
US
I would like to get rid of the last comma when a query is returned:

<cfoutput query="QofQ">#color#, </cfoutput>

So if I have 3 entries; red, green, blue...

The CF output is "red, green, blue,"

How can I get rid of the last comma?

Thanks
 
instead of doing a query output, can you do a ValueList()?

#ValueList(QofQ.color)#

that will put commas where they go.

=========================================
Don't sweat the petty things and don't pet the sweaty things.
 
I am not familar with the ValueList() command.

Do I need to place commas in the database?

#ValueList(QofQ.color)# Where do I insert the commas?

Thanks!
 
you dont.. your original example loops over a query where you output each single value with a comma - this function does not require the loop, it gets all values from that column of your query and comma-separates them for you.

if your not familiar with the function, look it up on liveDocs for a full explanation


=========================================
Don't sweat the petty things and don't pet the sweaty things.
 
Thanks for your help, your idea works great for one column in a database but i have two columns in the DB i need to put together.

I am creating a JS function for Google maps where I want the end result to look like this:

Code:
var pointsArray = [new GLatLng(39.116699, -105.713997), new GLatLng(39.924764, -105.155873), new GLatLng(39.907537, -105.071079), new GLatLng(39.933751, -105.163547), ];

But without the trailing comma at the very end.

Here is what I used to generate the above resulting code:
Code:
var pointsArray = [<cfoutput>new GLatLng(#latitude#, #longitude#), </cfoutput>];

I tried using the ValueList() command but it only seems to take on argument. Below code doesn't work.

Code:
var pointsArray = [<cfoutput>#ValueList(new GLatLng(QofQ.latitude, QofQ.longitude))#</cfoutput>];

Any other ideas?

 
<cfset strlatlong = "">
<cfoutput query="QofQ">
<cfset strlatlong = strlatlong & "new GLatLng("&latitude&
"," & longitude&"),">
</cfoutput>
<cfset strlatlong = mid(strlatlong,1,len(strlatlong)-1)>
<cfoutput>
var pointsArray = [#strlatlong#];
</cfoutput>

HTH,

Phil Hegedusich
Senior Programmer/Analyst
IIMAK
-----------
I'll have the roast duck with the mango salsa.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top