By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,950 Members | 1,019 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,950 IT Pros & Developers. It's quick & easy.

Multilingual database - using a variable instead of a column name in Mysql

P: 3
I have following code snippet to implement a multilingual website.
Idea is to, depending on user's language i need to translate word "Man" to "Hombre"

My Question: Will it be valid to use $user_language instead of hard coded column name "Spanish" here.

Expand|Select|Wrap|Line Numbers
  1. //$user_language is passed from his profile after log in to the site
  3. SELECT $user_language                     
  4. FROM TranslationTable                    
  5. WHERE  English=Man

English Spanish
Man Hombre

Mar 16 '13 #1
Share this Question
Share on Google+
2 Replies

Expert 100+
P: 1,031
You did not define your database correct.

More correct would be:
Language Word
English Man
Spanish Hombre

But than you will need an extra identifier to link these together like:
Language Id Word
English 123 Man
Spanish 123 Hombre
English 124 Horse
Spanish 124 Caballo

A query to get the translation for 'Man' would be:
Expand|Select|Wrap|Line Numbers
  1. SELECT S.Word
  2. FROM table E
  3. JOIN table S ON E.Id=S.Id and S.Language='Spanish'
  4. WHERE E.Language='English' and E.Word='Man'
Apr 1 '13 #2

Expert Mod 10K+
P: 12,347
It looks like you're mixing PHP and MySQL.... if you're using PHP to pass a query to your database, then I need to move this to the PHP forum. If you are using a different scripting language, I need to know what that is so I can move it.
Apr 1 '13 #3

Post your reply

Sign in to post your reply or Sign up for a free account.