1 回答
TA贡献1836条经验 获得超4个赞
好吧,我终于放慢了速度,逐个元素地遍历迭代并弄清楚了。
提供与给定线程相关的一系列帖子,例如:
[0] => Array
(
[post_id] => 5
[thread_id] => 5
[parent_id] => 0
[user_id] => 9
[post_message] => First message of thread number 5
[post_created] => 2019-06-29 20:54:59
[thread_title] => Thread Number 5
)
[1] => Array
(
[post_id] => 6
[thread_id] => 5
[parent_id] => 5
[user_id] => 9
[post_message] => First response to post 5
[post_created] => 2019-06-29 21:39:00
[thread_title] => Thread Number 5
)
[2] => Array
(
[post_id] => 7
[thread_id] => 5
[parent_id] => 5
[user_id] => 9
[post_message] => Second response to post 5
[post_created] => 2019-06-29 21:52:00
[thread_title] => Thread Number 5
)
[3] => Array
(
[post_id] => 8
[thread_id] => 5
[parent_id] => 6
[user_id] => 0
[post_message] => First response to post 6
[post_created] => 2019-06-29 21:55:00
[thread_title] => Thread Number 5
)
进入以下方法:
public function buildForum($postsToThread, &$forum, $parent_id = 0) {
foreach ($postsToThread as $post) {
$time = strtotime($post['post_created']);
$tmpCurrentAuthorName = $this->getPostAuthor($post['user_id']);
$tmpCurrentThreadTitle = $post['thread_title'];
$tmpCurrentPostDate = date("M d, Y g:i A", $time);
if ($post['parent_id'] == $parent_id) {
$forum .= "<ol><li><a href='/freetools/forumViewPost/" .$post['post_id'] . "'>" . $tmpCurrentThreadTitle .= " by " . $tmpCurrentAuthorName . "</a> on " . $tmpCurrentPostDate . "</li>";
$parent_id = $post['post_id'];
$this->buildForum($postsToThread, $forum, $parent_id);
$parent_id = $post['parent_id'];
$forum .= "</ol>";
}
}
}
- 1 回答
- 0 关注
- 109 浏览
添加回答
举报