Solved

Expand variable embedded inside an sql table

Posted on 2006-11-08
3
313 Views
Last Modified: 2013-12-24
How can I expand a variable which is embedded within a table column, itself expanded by a cfquery output?

A query, FilesInfo.description, is enclosed with cfoutput tags (see below). This is a column inside my sql table, data type varchar.

I want to edit the contents of FilesInfo.description and insert a variable in the middle of the text. When FilesInfo.description is expanded, the new variable is also expanded.

I guess you can see this as a variable within a variable, and it seems to me I read one cannot do this. But I'm hoping there is another way.

Here's the contents of "filesInfo.description".

"Story of a group of filmmakers traveled to Skull Island. <cfoutput>#variable#</cfoutput> They intended to investigate legends of a giant gorilla named Kong."

The problem is when expanded, #FilesInfo.description# displays my embedded variable name like this:

"This is the story of a group of explorers and documentary filmmakers traveled to Skull Island.  #variable# There they intend to investigate legends of a giant gorilla named Kong."

The variable is not expanded. Is there a workaround or a different method to do this without having to change my database design?


<cfquery name="FilesInfo" datasource="Library">
  select description
  from areas
  where area_id = #area_id#
</cfquery

<cfoutput>#FilesInfo.description#</cfoutput>

  - Georgia


0
Comment
Question by:RollinNow
3 Comments
 
LVL 2

Expert Comment

by:pegarm
ID: 17904925
Try this:

<cfquery name="FilesInfo" datasource="Library">
  select description
  from areas
  where area_id = #area_id#
</cfquery

<cfoutput>#evaluate(FilesInfo.description)#</cfoutput>
0
 
LVL 4

Accepted Solution

by:
CodeParadise earned 500 total points
ID: 17905110
The evaluate function wasn't working in my testing. You can also approach your problem this way.

<cfquery name="FilesInfo" datasource="Library">
  select description
  from areas
  where area_id = #area_id#
</cfquery

<cfset var = "12345678">
<cfset newText = Replace(FilesInfo.description, "##variable##", var)>
<cfoutput>#newText#</cfoutput>
0
 

Author Comment

by:RollinNow
ID: 17909968
CodeParadise,

The evaluate function didn't work for me either, but your solution does. I should have thought of it. Makes sense.  However, to get it to work for me, I had to do this:

<cfset newText = Replace(FilesInfo.description, "babygunk", "#var#", "ALL")>

babygunk is just some text I know I'll never use so it's unique and does not need to be a set variable.  It replaces babygunk with my defined variable, var.

 Thanks for your help, and thanks, pegarm, for the attempt.


   - Georgia
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Most ColdFusion developers get confused between the CFSet, Duplicate, and Structcopy methods of copying a Structure, especially which one to use when. This Article will explain the differences in the approaches with examples; therefore, after readin…
Introduction This article explores the design of a cache system that can improve the performance of a web site or web application.  The assumption is that the web site has many more “read” operations than “write” operations (this is commonly the ca…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question