2

我正在创建一个类似于 facebook 的评论后系统的系统。我首先使用codeigniter。

我需要使用 3 个表来获取所有数据。(来自用户的用户名,来自帖子的帖子,来自评论的评论)

$data = $this->post_model->getPosts();

        foreach ($data as $data) {
            $user = $this->members_model->memberData($data['uye']);
            $comments = $this->post_model->getComments($data['id']);
            $new_data[] = array('nick' => $user['nick'], 'post' => $data['post'], 'comments'=>$comments);
        }

输出

Array (
     [0] => Array (
              [nick] => yusufalibozkir 
              [post] => try.
              [comments] => Array (
                             [0] => Array (
                                    [id] => 1 
                                    [user] => 1 
                                    [comment] => comment try 
                                    [post] => 1
                                   )
                             )
             )
      )

我想将 1 的用户参数拆分为 id 为 1 的用户名。您有什么建议?

4

1 回答 1

0

这个问题非常不清楚,但你的意思是这样的吗?

$alldata = $this->post_model->getPosts();

    foreach ($alldata as $data) {
        $user = $this->members_model->memberData($data['uye']);
        $comments = $this->post_model->getComments($data['id']);
        $comments['id'] = $user['nick'];
        $new_data[] = array('nick' => $user['nick'], 'post' => $data['post'], 'comments'=>$comments);
    }
于 2013-05-01T12:44:32.970 回答