Solved

help retrieving text for selected language

Posted on 2009-07-06
8
132 Views
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
dsp_home_english.cfm
dsp_home_French.cfm

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

#lmsg.1#
#lmsg.2#


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

</cfquery>

<cfelseif request.language is "french">

<cfquery name="lmsg" datasource="#application.DS#" username="#application.dbuser#" password="#application.dbpass#">

SELECT     MessageID, French as mtext

FROM         tblMessages

</cfquery>

</cfif>

Open in new window

0
Comment
Question by:Shawn
  • 5
  • 3
8 Comments
 
LVL 1

Author Comment

by:Shawn
ID: 24790861
or maybe there's a better approach to this. I'm open to suggestions.
0
 
LVL 27

Expert Comment

by:azadisaryev
ID: 24791531
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...


Azadi
0
 
LVL 1

Author Comment

by:Shawn
ID: 24791901
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. :)

0
 
LVL 27

Accepted Solution

by:
azadisaryev earned 500 total points
ID: 24792048
you can use array notation to output data from a specific row in a query:

queryname['columnname'][rownumber]

so, in your case, that would be:

<cfoutput>#lmsg['mtext'][2]#</cfoutput>

IF the value 'HOME' is returned in the 2nd row of your query - remember that rownumber does not necessarily equal ID of the record!

Azadi
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 1

Author Comment

by:Shawn
ID: 24792068
getting closer. I really can't rely on the row though.

I think there might be something we can use here
http://www.experts-exchange.com/Software/Server_Software/Web_Servers/ColdFusion/Q_22013427.html#a17669834
0
 
LVL 1

Author Comment

by:Shawn
ID: 24800703
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>
</cfloop>

then:
cfoutput> #variables.FieldLabels['2']#</cfoutput>
0
 
LVL 27

Expert Comment

by:azadisaryev
ID: 24801145
good job!

Azadi
0
 
LVL 1

Author Comment

by:Shawn
ID: 24801164
thank you. works nicely.

feel free to jump in on this one. not sure how to approach it.
http://www.experts-exchange.com/Software/Server_Software/Web_Servers/ColdFusion/Q_24551955.html
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

In our day to day coding, how many times have we come across a necessity to check whether a URL is a broken link or not? For those of you that answered countless and are using ColdFusion like myself, then this article is for you.  It will show yo…
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…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

762 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now