Reputation: 2852
I'm using codeigniter and trying to subtract one of my input values from the database with no luck. My 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 get this Error:
Severity: Notice
Message: Array to string conversion
Filename: models/inventory.php
Upvotes: 0
Views: 405
Reputation: 2852
Found a solution:
$ItemName = $this->input->post('f2');
$query = $this->db->select('Stock')->from('inventory')->get();
foreach ($query->result() as $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 for your guys' help.
Upvotes: 1
Reputation: 538
try this code i make im not sure this will work but i think i give you an idea
function update(){
$newstock = "Stock-".$this->input->post('f2');
$itemname = $this->input->post('f1');
$data = array("stock" => $newstock);
$this->db->where('ItemName',$itemname);
$this->db->update('inventory', $data);
}
Upvotes: 0