Muhammad Usman Muhammad Usman - 1 year ago 80
PHP Question

Fetch All Records against id's in Codeigniter

When I retrieve the data from database the output is following
enter image description here

I want to fetch records against these id's but when I try in my controller with for each it gives me only 1 record back
Here is my code

//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);

when i print
it gives me only one record

Answer Source

Put it in an array so that it doesn't overrides on every loop. I guess this should solve it -

$results['post_list'][] = $this->Model_Frontend_Posts->get($post_id);

instead of

$results['post_list'] = $this->Model_Frontend_Posts->get($post_id);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download