Aggiorna il valore della tabella delle colonne in Codeigniter con array [duplicato]

Aug 16 2020

Ho la funzione per la tabella di aggiornamento come di seguito

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

Funziona bene ma voglio aggiornare la colonna total_pending con total_pending + $ amount ma dà un errore come

A non-numeric value encountered

qualcuno può aiutarmi a risolvere il problema? Grazie

Risposte

1 DilipPatel Aug 17 2020 at 05:55

puoi usare in questo modo perché total_pending è il nome della colonna

$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

Basta cambiare il metodo di aggiornamento BULK con $ query-> set e includere questo codice lì

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

Prova a utilizzare uno dei metodi seguenti:

Se desideri impostare le colonne individualmente, puoi impostare alcune condizioni if ​​su queste:

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

Oppure puoi provare il metodo seguente inviando tutte le colonne in un singolo array:

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