Solved

help retrieving text for selected language

Posted on 2009-07-06
8
133 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
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

Give your grad a cloud of their own!

With up to 8TB of storage, give your favorite graduate their own personal cloud to centralize all their photos, videos and music in one safe place. They can save, sync and share all their stuff, and automatic photo backup helps free up space on their smartphone and tablet.

Question has a verified solution.

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

Suggested Solutions

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…
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

910 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

21 Experts available now in Live!

Get 1:1 Help Now