我要做什么:
尝试从表“付款”到“付款历史”中克隆数据(更新)
付款表
Payment_ID
Payment_Amount
Payment_Method
Payment_Remark
付款历史记录表
Payment_ID
PaymentHistory_ID
Payment_Amount
Payment_Method
Payment_Remark
两者具有相同的列和相同的数据类型
我的代码: 控制器
public function updateHistory($Payment_ID){
$this->db->select('*');
$this->db->from('Payment');
$this->db->where('Payment_ID', $Payment_ID);
$query = $this->db->get();
$this->db->update('PaymentHistory',$query);
}
答案 0 :(得分:0)
您可以这样做:
$query = $this->db->where('Payment_ID', $Payment_ID)->get('Payment');
foreach ($query->result() as $row) {
$this->db->where('Payment_ID', $row->Payment_ID)->update('PaymentHistory', $row); // To update existing record
//$this->db->insert('PaymentHistory',$row); // To insert new record
}