mysql - Subtract PHP variable from DB -


i'm using codeigniter , trying subtract 1 of input values database no luck. current model is:

    $newstock = $this->input->post('f2');             $itemname = $this->input->post('f1');             $this->db->where('itemname', $itemname);              $this->db->set('stock', 'stock-'.[$newstock], false); 

i error:

severity: notice  message: array string conversion  filename: models/inventory.php 

found solution:

   $itemname = $this->input->post('f2');     $query = $this->db->select('stock')->from('inventory')->get();     foreach ($query->result() $row)         {              $row->stock;          }         $oldstock = $row->stock;         $numtosub = $this->input->post('f2');         $numtosub;         $newstock = $oldstock - $numtosub;          $newstock;      $data = array('itemname' => $this->input->post('f1'),                       'stock' => $newstock,                     );     $data2 = array('itemname' => $this->input->post('f1'),                       'quantitysold' => $this->input->post('f2'),                       'date' => standard_date()                     );             $this->db->insert('transactions', $data2);             $itemname = $this->input->post('f1');             $this->db->where('itemname', $itemname);              $this->db->update('inventory', $data); 

thanks guys' help.


Comments

Popular posts from this blog

c# - How to get the current UAC mode -

postgresql - Lazarus + Postgres: incomplete startup packet -

javascript - Ajax jqXHR.status==0 fix error -