我想要针对这些id获取记录但是当我尝试使用我的控制器时,它只给我一条记录 这是我的代码
//fetch all the posts relative to user in session
$post_id['id'] = $this->message_model->get_post($id);
echo '<pre>'; print_r($post_id['id']);die;
foreach ($post_id['id'] as $key) {
$post_id = $key['post_id'];
$results['post_list'] = $this->Model_Frontend_Posts->get($post_id);
}
当我打印$results['post_list']
时,它只给我一条记录
答案 0 :(得分:1)
$post_id['id'] = $this->message_model->get_post($id);
$array = array_column($post_id['id'], 'post_id'));
foreach ($array as $value) {
$results['post_list'] = $this->Model_Frontend_Posts->get($value);
}
中的array_column
答案 1 :(得分:0)
将它放在一个数组中,以便它不会覆盖每个循环。我想这应该解决它 -
$results['post_list'][] = $this->Model_Frontend_Posts->get($post_id);
而不是
$results['post_list'] = $this->Model_Frontend_Posts->get($post_id);