i have an array of id's through which i have to fetch data from two tables basically now let break my issue step by step
First step i have to get the id's of whom i want the data, this is the model that returns data of id's
function child_get($id){
$this->db->select("id");
$this->db->from('generic_table');
$this->db->where("parent",$id);
$query = $this->db->get();
return $query->result_array();
}
this return an array of ids in the following format
Array ( [0] => Array ( [id] => 13 ) [1] => Array ( [id] => 14 ) )
i have no issue so far now i have to traverse this array and dynamically add data into array depending on the id's for this i used a foreach loop
$arrOfIds = $data['child1'];
foreach($arrOfIds as $row) {
$data['child3']=array
(
"id" => $row["id"],
"path" => $this->Menu->test_maindata($row["id"])
);
}
the model used inside foreach
public function test_maindata($id)
{
$this->db->select("path");
$this->db->from('main_data');
$this->db->where("f_key",$id);
$query = $this->db->get();
return $query->result_array();
}
now the first issue it overriding the every value of iteration and returning only the last value see below
Array ( [id] => 14 [path] => Array ( [0] => Array ( [path] => almond.jpg ) ) )
you can see it skipped the iteration of id 13
secondly can i make this array in the following pattern
Array( [0] => Array( id=> 13, path=>bluebery.jpg) [1]=> Array( id=> 14, path=>almond.jpg));