I am fetching news items from posts table in foreach loop and attachments related to any this item are being fetched from attachments table .
i want to structure array like this
Array
(
[news] => stdClass Object
(
[id] => 95
[date] => 2016-07-29
[title] => This is first news
[content] => This is first news details
[type] => news
['attachment'] => stdClass Object
(
[id] => 25
[attachment_id] => 95
[type] => news
[path] => Jellyfish23.jpg
)
)
this is how i am doing my loop
$posts=$this->db->get_where('posts',array('type'=>$type));
if($posts->num_rows()>0){
foreach ($posts->result() as $key=> $value) {
echo $value->id;
$res['news']=$posts->row();
$result = $this->db->get_where('attachments', array('attachment_id'=>$value->id));
$res['attachment']= $result->row();
}
}
this is what i get
Array
(
[news] => stdClass Object
(
[id] => 95
[date] => 2016-07-29
[title] => This is first news
[content] => This is first news details
[type] => news
)
[attachment] => stdClass Object
(
[id] => 25
[attachment_id] => 97
[type] => news
[path] => Jellyfish23.jpg
)
)
Now how do i modify my code in a way that each news item and attachment related to that news are formatted properly as i mentioned above