how I can use array in cell related with another table in database like ?
Users table:
Name | languages_id
Anas | 1,2,3
Languages table:
id | language
1 | English
2 | Arabic
it’s work or not ?! and do you know what can I use in yii to do this ?
Don't do this.
Don't store mutiple items as comma separated column, it is really bad.
You should keep your tables normalized, by creating a new table UsersLanguages
as a many to many table between the USERS
and Languages
table. Somrthing like this:
Users
:
UserId
,UserName
,Languages
:
LanguageId
,LanguageName
,UserLanguages
:
UserId
foreign key references Users(UserId)
,LanguageId
foreign kery references Languages(LanguageId)
.You can use FIND_IN_SET
.
SELECT
name,
language
FROM
users
INNER JOIN
languages ON FIND_IN_SET(languages.id, languages_id) != 0
GROUP BY
name
Although Mahmoud Gamal's comment would perhaps be the better way to go about it.