1
The problem: One of our sites has a messaging system between users, for this we have two tables: one that stores the messages between users and the other with users, follow the structures below,and with this data we need to display in the messages the name of all users to which the message was sent.
At first I thought I’d make a select for the messages and with the user id of this message generate another string of select’s within a while, but it seemed wrong to me and searching through the internet I found no alternative to this situation. Would anyone have a solution to this problem? It would have to do a single select to get both users' names and the message?
Follow the structures:
TABLE messages:
- id INT PRIMARY KEY,
- id_users: 'Relates to user id, Ex: 1,27,1247,88',
- title 'message title',
- text 'from the message',
TABLE users:
- id INT PRIMARY KEY,
- name 'user name',
- etc..
the problem is that this query returns me only the name of one of the users and a message can have up to 20 users linked to it... =/
– MateusDemboski
Opa, Perai, now that I realize, the value of the id_users field is a string with the ids separated by comma?
– rafaels88
That’s right @rafaels88!
– MateusDemboski
I’ll edit my answer for you.
– rafaels88