Is there any more efficient to update the database value? Is there any more efficient to update the database value? codeigniter codeigniter

Is there any more efficient to update the database value?


Running a query within a loop is usually not a good idea. Instead, you can set the new value to qty + $qty by concatenating the variable to the string.

function updateQty($qty, $kode) {    $this->db->set('qty', 'qty + '.(int)$qty);     $this->db->where(['kode' => $kode, 'username' = >$this->session->userdata('username')]);    $this->db->update('temp'); }