?
Solved

help retrieving text for selected language

Posted on 2009-07-06
8
Medium Priority
?
138 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
[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
  • 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
Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

 
LVL 27

Accepted Solution

by:
azadisaryev earned 2000 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
 
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

Enroll in August's Course of the Month

August's CompTIA IT Fundamentals course includes 19 hours of basic computer principle modules and prepares you for the certification exam. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

Article by: kevp75
Hey folks, 'bout time for me to come around with a little tip. Thanks to IIS 7.5 Extensions and Microsoft (well... really Windows 8, and IIS 8 I guess...), we can now prime our Application Pools, when IIS starts. Now, though it would be nice t…
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…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses

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