Cập nhật giá trị bảng cột trong Codeigniter bằng mảng [trùng lặp]

Aug 16 2020

Tôi có chức năng cho bảng cập nhật như bên dưới

$update_data = array( 'total_pending'=>$amount,
                    'total_received'=>0,
                    'total_send'=>0,
                    'my_wallet'=>0,
                    'spen_in_app'=>0,
                    'check_in'=>0,
                    'upload_video'=>0,
                    'from_fans'=>0,
                    'purchased'=>0
                );

Nó hoạt động tốt nhưng tôi muốn cập nhật cột total_pend với tổng_dụng + $ số tiền nhưng lỗi của nó như

A non-numeric value encountered

bất cứ ai có thể xin vui lòng giúp tôi giải quyết vấn đề? Cảm ơn

Trả lời

1 DilipPatel Aug 17 2020 at 05:55

bạn có thể sử dụng như thế này bởi vì total_pend là tên cột

$update_data = array( 'total_pending'=> `total_pending` + $amount,
                    'total_received'=>0,
                    'total_send'=>0,
                    'my_wallet'=>0,
                    'spen_in_app'=>0,
                    'check_in'=>0,
                    'upload_video'=>0,
                    'from_fans'=>0,
                    'purchased'=>0
                );
Armnature Aug 17 2020 at 07:47

Chỉ cần thay đổi phương pháp cập nhật BULK với $ query-> set và đưa mã này vào đó

$this->db->set('total_pending', "total_pending+$amount");
AnkitJindal Aug 17 2020 at 05:08

Hãy thử sử dụng một trong các phương pháp dưới đây:

Nếu bạn muốn đặt các cột riêng lẻ, bạn có thể đặt một số điều kiện if trên những điều kiện sau:

$this->db->set('total_received', 0); $this->db->set('my_wallet', 0);
$this->db->set('total_send', 0); $this->db->set('from_fans', 0);
$this->db->set('my_wallet', 0); $this->db->set('check_in', 0);
$this->db->set('purchased', 0); $this->db->set('upload_video', 0);
$this->db->set('spen_in_app', 0); $this->db->where(condition); //like ('id', $id) $this->db->set('total_pending', "total_pending+$amount"); $this->db->update('tablename');

Hoặc bạn có thể thử phương pháp dưới đây để gửi tất cả các cột trong một mảng:

$update_data = array( 'total_pending'=> `total_pending` + $amount,
                    'total_received'=>0,
                    'total_send'=>0,
                    'my_wallet'=>0,
                    'spen_in_app'=>0,
                    'check_in'=>0,
                    'upload_video'=>0,
                    'from_fans'=>0,
                    'purchased'=>0
                );