Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

help retrieving text for selected language

Posted on 2009-07-06
8
Medium Priority
?
139 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
Understanding Web Applications

Without even knowing it, most of us are using web applications on a daily basis. Gmail and Yahoo email, Twitter, Facebook, and eBay are used by most of us daily—and they are web applications. We often confuse these web applications tools for websites.  So, what is the difference?

 
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

Looking for a new Web Host?

Lunarpages' assortment of hosting products and solutions ensure a perfect fit for anyone looking to get their vision or products to market. Our award winning customer support and 30-day money back guarantee show the pride we take in being the industry's premier MSP.

Question has a verified solution.

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

Lease-to-own eliminates the expenditure of hardware replacement and allows you to pay off the server over time. Usually, this is much cheaper than leasing servers. Think of lease-to-own as credit without interest.
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…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses

610 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