After completing process of data in temporary(costing_detail_temp) table,
I have to insert that data into a row in permanent(costing_detail) table with some additional column values. costing_detail table has same columns of costing_detail_temp with some additional columns. So, I have to do the following :
- Run a query into costing_detail_temp and select a row,
- Add some key-value pair into the returned array,
Insert into costing_detail. So, here is the code of my model:
function add_new_detail($Temp_id) { $loggedUserID = $this->session->userdata('id_user'); $added_on = date('Y-m-d H:i:s'); $added_date = date('Y-m-d'); $ip = $this->input->ip_address(); $qry = "SELECT * FROM costing_detail_temp WHERE Temp_id = ".$Temp_id; $query = $this->db->query($qry); $data_item_list = $query->result(); $additional_data = array( 'added_by' =>$loggedUserID, 'added_on' =>$added_on, 'added_date' =>$added_date, 'operation_ip' =>$ip ); //push the array $additional_data in $data_item_list array_push($data_item_list, $additional_data); //********** //insert a row with the combined array $this->db->insert('costing_detail', $data_item_list); return $data_item_list; }
This returns the following array:
Array
(
[0] => stdClass Object
(
[Temp_id] => 20160300101
[Quotation_id] => 201603001
[item_name] => BYA :3x 3 re (3-w) Red
[item_id] => 0
[Item_Specification] => core=3, wire=3, insulation=pvc, dia=3mm, color=red
[Required_Quantity] => 3.00
)
[1] => Array
(
[added_by] => 12
[added_on] => 2016-04-04 12:15:47
[added_date] => 2016-04-04
[operation_ip] => 127.0.0.1
)
)
However,I need something like this :
Array
(
[0] => stdClass Object
(
[Temp_id] => 20160300101
[Quotation_id] => 201603001
[item_name] => BYA :3x 3 re (3-w) Red
[item_id] => 0
[Item_Specification] => core=3, wire=3, insulation=pvc, dia=3mm, color=red
[Required_Quantity] => 3.00
[added_by] => 12
[added_on] => 2016-04-04 12:15:47
[added_date] => 2016-04-04
[operation_ip] => 127.0.0.1
)
)
How can i achieve this?