[英]Codeigniter Clone Data from table and update it (with Array)
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 : 假设“付款”表的名称为“
payment
而“付款历史”表的名称为“ payment_history
,则可以尝试如下操作:
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
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.