[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

How do I display coldfusion and html that I am pulling out of a database query?

Posted on 2009-03-31
9
Medium Priority
?
331 Views
Last Modified: 2013-12-24
I am attempting to create a template of a html table that also has #coldfusion# #variables# inside the table  and  i have stored the code  into a collumn in a sql table.

When i go to access the data  on a .cfm  page:
<cfquery....name="getcontent">
Select content from tablename
</cfquery
   <cfset table = "#getcontent.content#">

<body>
<cfoutput>#table#</cfoutput>
</body>
</html>

This concept seems to work it displays the data fine accept for the coldfusion variables which are in cfoutputs in the table.

Here is whats  in the database as table:

<table width="785" border="0" cellspacing="0" cellpadding="0" align="center">
      <tr>
      <td><cfoutput><img src="#banner#.jpg" width="785" height="187"></cfoutput></td>
      </tr>
      <tr> ...........
</table>

I need to know how to call the variable #table# and use the contant as html  and be able to output within the content as show above.





0
Comment
Question by:LeadCo
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
  • +1
9 Comments
 
LVL 27

Accepted Solution

by:
azadisaryev earned 2000 total points
ID: 24036368
the only sure way to do it is to write the variable to file and then cfinclude it:

<cfquery....name="getcontent">
Select content from tablename
</cfquery>
<cffile action="write" file="#expandpath("./")#somefilename.cfm" output="#getcontent.content#">
<body>
<cfinclude template="somefilename.cfm">
</body>
</html>

Azadi
0
 
LVL 13

Expert Comment

by:srikanthmadishetti
ID: 24036435
First thing remove <cfset table = "#getcontent.content#">

remove # in cfset you don't need them

second thing don't put double quotes here

<table width="785"

just write this as <table width=785 border=0 cellspacing=0 cellpadding=0 align=center>
      <tr>
      <td><cfoutput><img src=#banner#.jpg width=785 height=187></cfoutput></td>
      </tr>
     
</table>

Third thing

Where are you declaring banner


you are printing banner  isn't it ? where are you setting the value for banner.


0
 

Author Comment

by:LeadCo
ID: 24036518
AZADI -  that works however I would like to be able to process the content without writing a new file to the directory every time the page loads, It is a high traffic page and I am afraid this could cause performance issues with never ending rewrites of the same page. Is there another way?

SS
0
Moving data to the cloud? Find out if you’re ready

Before moving to the cloud, it is important to carefully define your db needs, plan for the migration & understand prod. environment. This wp explains how to define what you need from a cloud provider, plan for the migration & what putting a cloud solution into practice entails.

 
LVL 27

Expert Comment

by:azadisaryev
ID: 24036736
writing a file and cfincluding it is the most effective, efficient and elegant way to do it.

you can try using tokens instead of cf variables in the content stored in your db and then parsing strings and raplacing tokens with variables values and doing all sorts of other string manipulation, but you will only find that it's gonna be slower, involve heaps of code, and error-prone.

there's been a recent thread on the same subject on adobe cf forums - the Advanced Techniques one - have a look (sorry, the forums won;t load now, so can't get a link for you. but the thread subject is "Variable within variable?")

you can try something like <cfoutput>#evaluate(getcontent.content)#</cfoutput> but you'll likely find out that it does not work...

Azadi
0
 
LVL 39

Expert Comment

by:gdemaria
ID: 24038617
I have a situation like this...   I allow the user to create their own email messages for notifications.  But there are certain values that they will want to populate automatically.  For example,  if writing a notice that an order has shipped, the user may want to include some values that vary each email such as the order number, the ship date and the person's name.   So I give them a set of  "variables" to use and swap in the values.

 Dear @firstName@,

 Your order number @orderNumber@ shipped on @shipDate@.   Blah Blah...


I simply do a replaceNoCase() on the email body with the values of the variables that I pull from the database.    I think it works really well.   I give them a preview screen so they can see if the variables don't get replaced (perhaps because of a type-o).

0
 
LVL 27

Expert Comment

by:azadisaryev
ID: 24040478
if all you have in your text are cf variables and NO cfml (cf tags or functions), then try this:

<cfoutput>#evaluate(de(getcontent.content))#</cfoutput>

Azadi
0
 
LVL 39

Expert Comment

by:gdemaria
ID: 24040805
One of the advantages of not using confusion variables is that the user cannot accidenlty (or on purpose) enter any other variable that you don't want them to display that happens to be used on the page (datasource, credit card number, email, phone...)

Of course this assumes that you are having your user input the variables, like in the situation with the mailing I ddescribed above.  If your application is different and the user does not touch the information, this may not be relevant.



0
 

Author Closing Comment

by:LeadCo
ID: 31565172
Thanks!
0
 
LVL 39

Expert Comment

by:gdemaria
ID: 24059300
Leadco, I am curious how you are solving this.   From your comment above, you are writing to a file every time the page loads, which means multiple users could be writing simultaneously.  You have to have unique file names for each user or get locked file issues, and of course, you need to clean up all those files...

Unless the file is not user specific, in which case you could keep one file name and write it only periodically, say once every hour.  
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

This article provides a case study on how our local youth baseball league deployed a new website, including the platform selection, implementation and benefits to the league.
When it comes to security, close monitoring is a must. According to WhiteHat Security annual report, a substantial number of all web applications are vulnerable always. Monitis offers a new product - fully-featured Website security monitoring and pr…
The purpose of this video is to demonstrate how to properly insert a Vimeo Video into a WordPress site or Blog. This will be demonstrated using a Windows 8 PC. Go to your WordPress login page. This will look like the following: mywebsite.com/wp…
The purpose of this video is to demonstrate how to reset a WordPress password if you are locked out and cannot reset the password. A typical use would be if you cannot access the email to which WordPress would send the password recovery email to…

649 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