Actualizar el valor de la tabla de columnas en Codeigniter con Array [duplicado]

Aug 16 2020

Tengo una función para actualizar la tabla como la siguiente

$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
                );

Está funcionando bien, pero quiero actualizar la columna total_pending con total_pending + $ amount pero da un error como

A non-numeric value encountered

¿Alguien puede ayudarme a resolver el problema? Gracias

Respuestas

1 DilipPatel Aug 17 2020 at 05:55

puede usar así porque total_pending es el nombre de la columna

$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

Simplemente cambie el método de actualización BULK con $ query-> set e incluya este código allí

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

Intente utilizar uno de los métodos siguientes:

Si desea establecer columnas individualmente, puede establecer algunas condiciones if sobre estas:

$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');

O puede probar el método siguiente enviando todas las columnas en una sola matriz:

$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
                );