问题
What i am trying to do:
Try to Clone Data (Update) from Table "Payment" to "Payment History"
Payment Table
Payment_ID
Payment_Amount
Payment_Method
Payment_Remark
Payment History Table
Payment_ID
PaymentHistory_ID
Payment_Amount
Payment_Method
Payment_Remark
Both have the same column and same data type
My Code: Controller
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);
}
回答1:
You can do like this:
$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
}
来源:https://stackoverflow.com/questions/56863760/codeigniter-clone-data-from-table-and-update-it