I have three tables that store data like this:
chat_id |
sqn_num |
name |
1 |
5 |
My Cool Chat |
2 |
3 |
Another Awesome Chat |
3 |
9 |
A Third Rockin' Chat |
chat_id |
user_id |
chat_id |
1 |
1 |
1 |
2 |
1 |
2 |
3 |
2 |
2 |
4 |
2 |
3 |
5 |
3 |
3 |
6 |
3 |
1 |
user_id |
name |
1 |
James Little |
2 |
Maddie Tucker |
3 |
Danny Little |
And I want a function where I can input user_id = 1
so it outputs data like this:
[
{
"chat_id": 1,
"sqn_num": 5,
"chat_name": "My Cool Chat",
"members": [
{
"user_id": 1,
"name": "James Little"
}
{
"user_id": 2,
"name": "Maddie Tucker"
},
]
},
{
"chat_id": 3,
"sqn_num": 9,
"chat_name": "A Third Rockin' Chat",
"members": [
{
"user_id": 1,
"name": "James Little"
},
{
"user_id": 3,
"name": "Danny Little"
}
]
}
]