首先对不起,如果问题不好,我的英语不太好。
我有以下查询
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
问题实际上是我想在同一页面上使用这些评论
所以它看起来像这样
parrent post 1
children comment 1
children comment 1
parrent post 2
children2 comment 1
children2 comment 1
我也在评论表中保存帖子ID(流ID是什么)并加入它们。
但是当我得到结果时,看起来像这样
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.
)
所以问题是,当我释放这些时,我得到的评论是分开的,是合并的?
所以我想看起来像这样
A
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.
)
有办法做到这一点吗? 可以请某人给我一个提示还是一个例子?
真的很开心
答案 0 :(得分:0)
很抱歉,但这是怎么回事。除非您将所有数据放在数组中,否则可以使用foreach或for语句按顺序浏览comment_text。
答案 1 :(得分:0)
数组中不能有两个具有相同名称的键。您需要在去的时候重命名密钥(可能会在末尾附加一个数字)
[comment_text_1] => comment one
[comment_text_2] => comment two
或者您可以将每个元素转换为像这样的子元素数组 - 这在代码
中更有用[comment_text] => array('comment one', 'comment two')