954,593 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Using #parameter# string of databases

Hello, I am newbie in Coldfusion development and I have a question:

I must make a application where I have to use a parameter in a database (and not written in the code).

Example: I have to show a text of a table with a "subtext" of other table. So I do this:

Table1:
id = 1
text = "This is an #qry_2.subtext#"

Table2:
id = 1
subtext = "example"

<cfquery datasource="#application.DSN#" name="qry_1">
      SELECT text FROM table1 WHERE id = 1
   </cfquery>

<cfquery datasource="#application.DSN#" name="qry_2">
      SELECT subtext FROM table2 WHERE id = 1
   </cfquery>

<cfoutput>#qry_1.text#</cfoutput>


But only appear "This is an #qry_2.subtext#", and not "This is an example". The Coldfusion can“t read the ## of the string of database and put the subtext of table2.

There is a solution to make the Coldfusion read a ## parameter of a database with process it?

Obs.: Sorry my poor english. I am brazilian. :)

Jeanioz
Newbie Poster
2 posts since Mar 2008
Reputation Points: 10
Solved Threads: 0
 

Sorry, but what you have there is not going to work. Trying to have dynamic content inside text stored in a database table is usually done with percent-sign delimited placeholders (or whatever your delimiter of choice happens to be). Here is an example:

First of all replace the text "#qry_2.subtext#" in table1 with "%placeholder%".
Store the value of qry_1.text in a temporary variable. I usually go with strTemp.
Replace the instances of %placeholder% with the value of qry_2.subtext.
Example:

<cfset strTemp = ReplaceNoCase(strTemp,"%placeholder%",qry_2.subtext,"all")>

Output strTemp.

I have used this technique on numerous occasions in the past and it always works for me.

hinde
Junior Poster in Training
60 posts since Jul 2005
Reputation Points: 10
Solved Threads: 4
 

The Replace function works! Thank you!

Jeanioz
Newbie Poster
2 posts since Mar 2008
Reputation Points: 10
Solved Threads: 0
 

I had a similar problem, and just wrapped the database field contents in:

#evaluate(de(dbfieldcontent))#

This works like a dream.

querner
Newbie Poster
1 post since Mar 2011
Reputation Points: 10
Solved Threads: 0
 

Most of the time, replace() is more efficient.

Geez.. this thread's like 3 years old!

arrgh
Posting Whiz
381 posts since Dec 2008
Reputation Points: 32
Solved Threads: 47
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You