內陣列結果我有3個表,PHP的MySQL的選擇,陣列結果
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 |
我的目標是與各自的評論數據和likers數據得到tbl_photo照片數據一起。我想陣列的結構如下凡在我有了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的一個查詢做到這一點?如果沒有,有沒有其他的方式來做到這一點?感謝你們!
是的,這將是最好的。 – deed02392 2012-02-08 12:11:49
嗨!謝謝!大幫人! – janusbalatbat 2012-02-08 12:17:04