Codeigniter Clone Data from table and update it

无人久伴 提交于 2019-12-25 01:12:45

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!