简体   繁体   中英

Codeigniter Clone Data from table and update it


Try to Clone Data (Update) from Table "Payment" to "Payment History"

Payment_ID
Payment_Amount
Payment_Method
Payment_Remark

Payment_ID
PaymentHistory_ID
Payment_Amount
Payment_Method
Payment_Remark

Both have the same column and same data type

My Code:

    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);

}

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
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM