Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CFset string concatenation (of query results)

Tags:

coldfusion

Is it possible to set a ColdFusion variable to a concatenated string?

<cfoutput query="getName">
   <cfset myName=#Firstname# #Lastname#>
</cfoutput>

Doesn't seem to work, nor does

<cfoutput query="getName">
   <cfset teacherName=#Firstname# + #Lastname#>
</cfoutput>
like image 877
redconservatory Avatar asked Jan 12 '12 19:01

redconservatory


2 Answers

If you really need an additional variable, ColdFusion's concatenation operator is &

 <cfset teacherName = Firstname &" "& Lastname>

Though for simple output, no extra variable is needed. Just output the column values:

<cfoutput query="getName">
   #Firstname# #Lastname# <br>
</cfoutput>
like image 186
Leigh Avatar answered Oct 05 '22 02:10

Leigh


As an alternative to using the ColdFusion & or &= string operators, you can also do the following:

<cfoutput query="getName">
    <cfset myName="#Firstname# #Lastname#">
    <p>#myName#</p>
</cfoutput>
like image 34
Micah Avatar answered Oct 05 '22 01:10

Micah