我正在创建一个类似于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的用户名。您的建议是什么?
答案 0 :(得分: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);
}