Using #parameter# string of databases

Thread Solved

Join Date: Mar 2008
Posts: 2
Reputation: Jeanioz is an unknown quantity at this point 
Solved Threads: 0
Jeanioz Jeanioz is offline Offline
Newbie Poster

Using #parameter# string of databases

 
0
  #1
Mar 20th, 2008
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"

  1. <cfquery datasource="#application.DSN#" name="qry_1">
  2. SELECT text FROM table1 WHERE id = 1
  3. </cfquery>
  4.  
  5. <cfquery datasource="#application.DSN#" name="qry_2">
  6. SELECT subtext FROM table2 WHERE id = 1
  7. </cfquery>
  8.  
  9. <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.
Reply With Quote Quick reply to this message  
Join Date: Jul 2005
Posts: 60
Reputation: hinde is an unknown quantity at this point 
Solved Threads: 4
hinde hinde is offline Offline
Junior Poster in Training

Re: Using #parameter# string of databases

 
0
  #2
Mar 22nd, 2008
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:
  1. <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.
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 2
Reputation: Jeanioz is an unknown quantity at this point 
Solved Threads: 0
Jeanioz Jeanioz is offline Offline
Newbie Poster

Re: Using #parameter# string of databases

 
0
  #3
Mar 24th, 2008
The Replace function works! Thank you!
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the ColdFusion Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC