468,550 Members | 2,465 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,550 developers. It's quick & easy.

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

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.

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

English Spanish
Man Hombre

Thanks
SW
Mar 16 '13 #1
2 1421
Luuk
1,043 Expert 1GB
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
Rabbit
12,513 Expert Mod 8TB
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.

Similar topics

3 posts views Thread by Martin Lucas-Smith | last post: by
2 posts views Thread by Elmar Grandel | last post: by
2 posts views Thread by deja | last post: by
2 posts views Thread by msnews | last post: by
reply views Thread by NPC403 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.