Hi stackoverflow community,
I want to know if its possible to eval a value as a field in a MySQL request.
Here is my problem:
I have a post
table (id, lg, text) and a lang
table (id, lg1, lg2, lg3). My post translations in lg1 / lg2 / lg3 are linked following the table lang
.
Example:
in lang
:
id: 1 - lg1: 1 - lg2: 2 - lg3: 7
in post
:
id: 1 - lg: lg1 - text: my text in lg1 language
id: 2 - lg: lg2 - text: my text in lg2 language
id: 7 - lg: lg3 - text: my text in lg3 language
Now I want to get all the translations from a post id (ex: 2) and a language (ex: lg2), here is my request:
select p.* from `post` p left join `lang` l on
(
(l.lg1 = p.id) or
(l.lg2 = p.id) or
(l.lg3 = p.id)
) where l.lg2 = 2;
But if I want to add a language, i'll have to change all my requests... If I could do something like that:
select p.* from `post` p left join `lang` l on
(l.eval(p.lg) = p.id)
where l.lg2 = 2;
it would be great.
Any idea?