I have two tables.
TABLE PRODUCT
product_id
category_id
product_name
TABLE CATEGORY
category_id
name_eng
name_ita
name_rus
When I save the information of the product into database, I choose the category from a list (previously created > TABLE CATEGORY). Each category has an ID and three fields (the name in English, Italian and Russian).
Now I would like to show the right category name depending on the language of the page.
How can I show the values of the second table (TABLE CATEGORY) depending on the value cat_id, which of course is the same for both tables?
Hope you can help me. Thanks, Alessandro
You could do something like
'SELECT *, name_'.$lang.' AS name '.
'FROM product AS p '.
'JOIN category AS c ON c.category_id = p.category_id'
where $lang is a php variable containing the language of the page (ita, eng or rus). In this way you will obtain a column called name with the correct category name
Using a JOIN:
SELECT tp.*. tc.* FROM `TABLE PRODUCT` tp JOIN `TABLE CATEGORY` ON tp.category_id=tc.category_id