Quantcast
Channel: Adobe Community: Message List - ColdFusion
Viewing all articles
Browse latest Browse all 21760

Re: How do I use a variable within paragraphFormat?

$
0
0

The first instance of 'FirstName' is a variable name. Whereas the last instance is a substring within the string defined by getInfo.message. I am assuming that the message you have saved in the database is:

 

"Hi"  & FirstName & ",

  We are writing to you to inform you that we received your request to schedule the...

 

You could modify the code as follows. Give the queries separate names, say, getUser and getMessage. Omit the columns userID and messID from the respective queries. This is because the where-clauses already specify the values.

 

What you could then do is replace the substring "  & FirstName & " in getMessage.message with the variable getUser.FName. The result would be something like

 

<!--- grabbing firstname --->

<CFQUERY Name="getUser" datasource="#application.dsn#">

SELECT fNname, lName, email, company, phone

FROM users

where userID = 1

</CFQUERY>

 

<cfset firstNameString = " " & trim(getUser.fName) & " ">

 

<!--- grabbing message --->

<cfquery name="getMessage" datasource="#application.dsn#">

select name, message

from messages

where messID = 1

</cfquery>

 

<table width="300" cellpadding="0" cellspacing="0" border="1">

<tr><td>

<cfoutput query="getMessage">

<cfset msg = replaceNoCase(message, '"  & FirstName & "', firstNameString)>

#paragraphFormat(msg)#

</cfoutput>

</td></tr>

</table>

 

Having said that, there are still 2 things I fail to understand. Firstly, why loop across the query when there is just one row? Secondly, why do you save a static message in the database when you could just save it in the CFML code as a string variable?


Viewing all articles
Browse latest Browse all 21760

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>