笨 - 克隆数据(但除去1列是不存在的)(Codeigniter - Clone Data (But

2019-10-29 07:54发布

我所试图做的事:
尝试克隆数据(更新)表“付款历史”到“付款”,但现在的问题是,在付款记录表有“PaymentHistory_ID”一栏,我怎么忽略它?

支付表

Payment_ID
Payment_Amount
Payment_Method
Payment_Remark

付款历史记录表

Payment_ID
PaymentHistory_ID
Payment_Amount
Payment_Method
Payment_Remark

两者具有相同的列和相同的数据类型

我的代码: 控制器

        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
}

    }

根据我所提供的问题从表笨克隆数据和更新 ,代码工作,但不是我所面临的新问题。

注:新来的CodeIgniter

Answer 1:

单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
        }

}


文章来源: Codeigniter - Clone Data (But remove 1 column that is not exist )