I have 3 tables,
tbl_photo tbl_photo_comments tbl_photo_likers
___________ ____________ _____________
| photo_id | | comment_id | | like_id |
| photo_url | | photo_id FK| | user_id FK |
| user_id FK| | user_id FK | | photo_id FK |
| comment |
My objective is to get the photos data from tbl_photo together with their respective comments data and likers data. The structure of the array I want is as below where in I have ONE result array that has 2 more arrays as elements on its data
oneResultArray =
{
photo_url = "www.url.com/photo.png";
photoID = 1;
user_id = 2
commentData = (
{
comment = "comment 1";
userid = 1
},
{
comment = "comment 2";
userid = 2
},
{
comment = "comment 3";
userid = 3});
likersData = (
{
userid = 2;
username = liker1;
},
{
userid = 3;
username = liker2;
});
},
{
photo_url = "www.url.com/photo.png";
photoID = 1;
user_id = 2
commentData = (
{
comment = "comment 1";
userid = 1
},
{
comment = "comment 2";
userid = 2
},
{
comment = "comment 3";
userid = 3});
likersData = (
{
userid = 2;
username = liker1;
},
{
userid = 3;
username = liker2;
});
}
my question is, Is it possible to accomplish this using one query on mysql? if not, is there any other way of doing this? thank you guys!