Codeigniter从表中克隆数据并更新它(使用数组)

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
Payment_Amount
Payment_Method
Payment_Remark

Both have the same column and same data type

My Code: Controller

public function updateHistory($Payment_ID){
    // with single Payment_ID

    //get data with specific column and ignore PaymentHistory_ID
    $query = $this->db->select('Payment_Amount','Payment_Method','Payment_Remark')->where('Payment_ID', $Payment_ID)->get('YOUR FROM TABLE');
    $result = $query->row_array();

    if($result)
    { // check if has data
        //then update to another table
        $this->db->where('Payment_ID', $Payment_ID)->update('YOUR TO TABLE', $result ); // To update existing record
    }

}

Table data

Payment               Payment History
+-----+---------+    +------+------------+---------+
| ID  | remark  |    | ID   |remark      | amount  |
+=====+=========+    +======+============+=========+
|  1  |100 done |    |   1  |  100 done  | 100     |
+-----+---------+    +------+------------+---------+
|  2  |200 done |    |   1  |  200 done  | 200     |
+-----+---------+    +------+------------+---------+
                     |  2  |  500 done   | 500     |
                     +------+------------+---------+

Trying to clone data with array Above is example for my table

Assuming the Payment table name is payment and the Payment History table name is payment_history, you could try it like below :

public function updateHistory($Payment_ID){
        // with single Payment_ID

        //get data with specific column and ignore PaymentHistory_ID
        $query = $this->db->select('Payment_Amount','Payment_Method','Payment_Remark')
        ->where('Payment_ID', $Payment_ID)
        ->get('payment');
        $result = $query->row_array();

        if($result)
        { // check if has data
            //then update to another table
            $this->db->where('Payment_ID', $Payment_ID)->update('payment_history', $result ); // To update existing record
        }

}