首先對不起,如果問題不好,我的英語不太好。php將Mysql查詢結果加入一個數組
我有以下查詢
SELECT
*
FROM
`stream_post`
LEFT JOIN `stream_comment`
ON (`stream_post`.`stream_id` = `stream_comment`.`comment_stream_id`)
JOIN `users_metadata`
ON (`stream_post`.`user_id` = `users_metadata`.`user_id`)
ORDER BY
`stream_id` DESC
LIMIT 10
並實際porblem是我想用這些意見在同一個頁面
上所以它看起來像這樣
parrent post 1
children comment 1
children comment 1
parrent post 2
children2 comment 1
children2 comment 1
我也保存帖子ID(什麼是流ID)我也是評論表,並加入他們。
但是當我得到的結果UT看起來像這樣
Array
(
[stream_id] => 1
[user_id] => 1
[stream_text] => dasdadada
[date] => 1346400535
[comment_id] => 1
[comment_stream_id] => 1
[comment_user_id] => 1
[comment_text] => comment one
[posted] => 0
[full_name] => Henry Marg
[gender] => 1
[location] => Los Angeles
[birth_year] => 2012
[birth_month] => 1
[birth_day] => 1
[work_location] => Tesco
[about] => Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of "de Finibus Bonorum et Malorum" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, "Lorem ipsum dolor sit amet..", comes from a line in section 1.10.32.
The standard chunk of Lorem Ipsum used since the 1500s is reproduced below for those interested. Sections 1.10.32 and 1.10.33 from "de Finibus Bonorum et Malorum" by Cicero are also reproduced in their exact original form, accompanied by English versions from the 1914 translation by H. Rackham.
)
Array
(
[stream_id] => 1
[user_id] => 1
[stream_text] => dasdadada
[date] => 1346400535
[comment_id] => 1
[comment_stream_id] => 1
[comment_user_id] => 1
[comment_text] => comment 2
[posted] => 0
[full_name] => Henry Marg
[gender] => 1
[location] => Los Angeles
[birth_year] => 2012
[birth_month] => 1
[birth_day] => 1
[work_location] => Tesco
[about] => Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of "de Finibus Bonorum et Malorum" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, "Lorem ipsum dolor sit amet..", comes from a line in section 1.10.32.
The standard chunk of Lorem Ipsum used since the 1500s is reproduced below for those interested. Sections 1.10.32 and 1.10.33 from "de Finibus Bonorum et Malorum" by Cicero are also reproduced in their exact original form, accompanied by English versions from the 1914 translation by H. Rackham.
)
所以問題是,當我freach這些,我得到分隔的評論,insted的合併而成?
,所以我想這個樣子
一個
rray
(
[stream_id] => 1
[user_id] => 1
[stream_text] => dasdadada
[date] => 1346400535
[comment_id] => 1
[comment_stream_id] => 1
[comment_user_id] => 1
[comment_text] => comment one
[comment_text] => comment two
[posted] => 0
[full_name] => Henry Marg
[gender] => 1
[location] => Los Angeles
[birth_year] => 2012
[birth_month] => 1
[birth_day] => 1
[work_location] => Tesco
[about] => Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of "de Finibus Bonorum et Malorum" (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, "Lorem ipsum dolor sit amet..", comes from a line in section 1.10.32.
The standard chunk of Lorem Ipsum used since the 1500s is reproduced below for those interested. Sections 1.10.32 and 1.10.33 from "de Finibus Bonorum et Malorum" by Cicero are also reproduced in their exact original form, accompanied by English versions from the 1914 translation by H. Rackham.
)
有沒有辦法做到這一點? 可以請別人給我一個提示或例子嗎?
會很開心
http://stackoverflow.com/questions/3116330/recursive-categories-with-a-single-query –
此鏈接:http://mikehillyer.com/articles/managing-hierarchical-data-in-mysql /可能會幫助你達到同樣的效果。 –