Codeigniter - Clone Data (But remove 1 column that

2019-08-20 06:22发布

问题:

What i am trying to do:
Try to Clone Data (Update) from Table "Payment History" to "Payment" , But the problem right now is that in Payment History Table there is "PaymentHistory_ID" column , how do I ignore it ?

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

$query = $this->db->where('Payment_ID', $Payment_ID)->get('PaymentHistory');
foreach ($query->result() as $row) {      
      $this->db->where('Payment_ID', $row->Payment_ID)->update('PaymentHistory', $row); // To update existing record
      //$this->db->insert('Payment',$row); // To insert new record
}

    }

Based on the question that I have provided Codeigniter Clone Data from table and update it , the codes works , but not the new problem that I am facing.

Note: New to CodeIgniter

回答1:

with single Payment_ID

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
        }

}