Solved

help retrieving text for selected language

Posted on 2009-07-06
8
134 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
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 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
 
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

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
website file permissions 4 71
Server specifications for web hosting 7 92
Website being blocked? 3 127
spamming  on Hosted svrs? 6 91
A web service (http://en.wikipedia.org/wiki/Web_service) is a software related technology that facilitates machine-to-machine interaction over a network. This article helps beginners in creating and consuming a web service using the ColdFusion Ma…
Meet the world's only “Transparent Cloud™” from Superb Internet Corporation. Now, you can experience firsthand a cloud platform that consistently outperforms Amazon Web Services (AWS), IBM’s Softlayer, and Microsoft’s Azure when it comes to CPU and …
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

831 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