We help IT Professionals succeed at work.

Check out our new AWS podcast with Certified Expert, Phil Phillips! Listen to "How to Execute a Seamless AWS Migration" on EE or on your favorite podcast platform. Listen Now


help retrieving text for selected language

Shawn asked
Medium Priority
Last Modified: 2013-12-24
I have a site in English and French and am trying to set it up to retrive the text from a table so I don't have 2 pages with the same code.

eg toady I have pages like

I now want to have one page called dsp_home.cfm and retrive the text from a table tblMessages.

I have set up the query below at the top of the the idex.cfm

My question is how do I call the text from the query.

eg if the language is set to English how would I get the text from this sample table:
ID      English      French
1      Hello      Bonjour
2      Home      Accueil


my query to get text for appropriate language:
<cfif request.language is "english"> 
<cfquery name="lmsg" datasource="#application.DS#" username="#application.dbuser#" password="#application.dbpass#">
SELECT     MessageID, English as mtext
FROM         tblMessages
<cfelseif request.language is "french">
<cfquery name="lmsg" datasource="#application.DS#" username="#application.dbuser#" password="#application.dbpass#">
SELECT     MessageID, French as mtext
FROM         tblMessages

Open in new window

Watch Question


or maybe there's a better approach to this. I'm open to suggestions.
if the value of request.language var matches the name of the language's db table column -depending on your db and os, table names may be case-sensitive - you could do something like this:

SELECT     MessageID, #request.language# as mtext
FROM         tblMessages

be very careful with this approach, though! it can leave you quiet open to SQLi, if you are not extremely careful about how request.language var gets set...



with my query I don't actually need the varialbe #request.language# though it is shorter.

What I am not sure how to do is retrieve say the ID 2. If the language was set to English how would I get "Home" to show in a variable like:      #lmsg.2#

I have tried: <cfoutput> Message is this: #lmsg.mtext# </cfoutput>
but this only gives me the first record ("Hello").

I'm pretty sure I've seen somewhere where if you put the ID or a unique name in th evariable you can output another field in the same record. eg for ID 2 >>> #lmsg.2# (or something similar) should output "Home".

hope this is a little clearer. :)

Unlock this solution with a free trial preview.
(No credit card required)
Get Preview


getting closer. I really can't rely on the row though.

I think there might be something we can use here


thanks Azadi,
that put me in the right direction. I ended up using:

right under the query: <!---  load into a structure --->
<cfloop query="lmsg">
  <cfset variables.FieldLabels[lmsg.MessageID] = lmsg.mtext>

cfoutput> #variables.FieldLabels['2']#</cfoutput>
good job!



thank you. works nicely.

feel free to jump in on this one. not sure how to approach it.
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a free trial preview!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.