在完成臨時(costing_detail_temp
)表中的數據處理後,
我必須將該數據插入永久(costing_detail
)表中的某行並附加一些列值。 costing_detail
表具有與其他列相同的costing_detail_temp
列。所以,我一定要做到以下幾點:Codeigniter重建查詢輸出數組插入到另一個表
- 運行查詢到costing_detail_temp並選擇一排,
- 添加一些鍵值對到返回數組,
插入costing_detail。 所以,這裏是我的模型的代碼:
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; }
這將返回以下陣列:
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 ) )
不過,我需要這樣的:
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 ) )
如何我可以做到這一點嗎?
return $ data_item_list;未定義,請將其重命名爲$ data_itemlist –