อัปเดตค่าตารางคอลัมน์ใน Codeigniter ด้วย Array [ซ้ำกัน]
Aug 16 2020
ฉันมีฟังก์ชั่นสำหรับอัพเดตตารางดังต่อไปนี้
$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
);
ใช้งานได้ดี แต่ฉันต้องการอัปเดตคอลัมน์ total_pending ที่มี total_pending + $ จำนวน แต่ให้ข้อผิดพลาดเช่น
A non-numeric value encountered
ใครก็ได้โปรดช่วยฉันแก้ปัญหานี้? ขอบคุณ
คำตอบ
1 DilipPatel Aug 17 2020 at 05:55
คุณสามารถใช้แบบนี้ได้เนื่องจาก total_pending คือชื่อคอลัมน์
$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
เพียงแค่เปลี่ยนวิธีการอัปเดตจำนวนมากด้วย $ query-> set และรวมรหัสนี้ไว้ที่นั่น
$this->db->set('total_pending', "total_pending+$amount");
AnkitJindal Aug 17 2020 at 05:08
ลองใช้วิธีใดวิธีหนึ่งด้านล่างนี้:
หากคุณต้องการตั้งค่าคอลัมน์ทีละคอลัมน์คุณสามารถตั้งค่า if เงื่อนไขเหล่านี้ได้:
$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');
หรือคุณสามารถลองใช้วิธีการด้านล่างในการส่งคอลัมน์ทั้งหมดในอาร์เรย์เดียว:
$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
);