Codeigniter-克隆数据(但删除1个不存在的列) [英] Codeigniter - Clone Data (But remove 1 column that is not exist )
本文介绍了Codeigniter-克隆数据(但删除1个不存在的列)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我要做什么:
尝试从表付款历史到付款中克隆数据(更新),但是现在的问题是付款中历史记录表中有 PaymentHistory_ID列,我该如何忽略它?
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_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
我的代码:
控制器
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从表中克隆数据并更新它
,代码有效,但不适用于我面临的新问题。
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.
注意:CodeIgniter的新手
Note: New to CodeIgniter
推荐答案
(具有单个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-克隆数据(但删除1个不存在的列)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文