【发布时间】:2012-02-29 19:22:48
【问题描述】:
我有 3 张桌子,
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 |
我的目标是从 tbl_photo 中获取照片数据以及它们各自的 cmets 数据和 likers 数据。我想要的数组结构如下,其中我有一个结果数组,其中有 2 个数组作为其数据的元素
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;
});
}
我的问题是,是否可以在 mysql 上使用一个查询来完成此操作?如果没有,有没有其他方法可以做到这一点?谢谢你们!
【问题讨论】:
标签: php mysql multidimensional-array