php - Adding objects to existing array in codeigniter -


in model there 2 functions data database. both return data arrays of objects.one function given below.

public function get_camaramens($data,$evdata) { $this->db->select('emp_position.employee_id'); $this->db->from('emp_position'); $this->db->where('emp_position.position','c'); $this->db->where('emp_position.employee_id not in ('.implode(",",$data).')'); $query=$this->db->get('',$evdata); return $query->result(); } 

in controller accept result follows.

$sdata['camaramen_list']    = $this->emp_position_model>get_camaramens($data,$evdata['no_of_cams']); 

the other function in model

public function get_camara_assistants($data,$sdata,$evdata) { $cdata = array(); foreach($sdata['camaramen_list'] $row) { $cdata[] = $row->employee_id; }  $this->db->select('emp_position.employee_id'); $this->db->from('emp_position'); $this->db->where('emp_position.position','ca'); $this->db->where('emp_position.employee_id not in ('.implode(", ",$data).')'); $this->db->where('emp_position.employee_id not in ('.implode(", ",$cdata).')'); $query=$this->db->get('',$evdata); return $query->result(); } 

in controller want add result of above function same array of objects $sdata. if put same name follows replace previous array.

$sdata['camaramen_list']    = $this->emp_position_model->get_camara_assistants($data,$sdata,$evdata['no_of_cams']); 

can tell me correct way please.

if use same variable, override. there 2 ways can that.

  1. array_merge @ controller

    you can merge 2 arrays array_merge.

    $result1 = $this->emp_position_model>get_camaramens($data,$evdata['no_of_cams']); $result2 = $this->emp_position_model->get_camara_assistants($data,$sdata,$evdata['no_of_cams']);  $combined_result = array_merge($result1, $result2); 
  2. union select @ model

    $this->db->select('emp_position.employee_id'); $this->db->from('emp_position'); $this->db->where('emp_position.position','c'); $this->db->where('emp_position.employee_id not in ('.implode(",",$data).')');  $compiled_1 = $this->db->get_compiled_select();   $this->db->select('emp_position.employee_id'); $this->db->from('emp_position'); $this->db->where('emp_position.position','ca'); $this->db->where('emp_position.employee_id not in ('.implode(", ",$data).')'); $this->db->where('emp_position.employee_id not in ('.implode(", ",$cdata).')');  $compiled_2 = $this->db->get_compiled_select();   $query = $this->db->query('( ' .$compiled_2 .' ) union ( '. $compiled_1 .' );' ); 

you can use $sdata['camaramen_list']['one'], $sdata['camaramen_list']['two'] if wanna create new index. otherwise, use way instead.

hope help.


Comments

Popular posts from this blog

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -