我正在使用codeigniter并尝试从数据库中减去我的输入值之一而没有运气。我当前的模型是:
$newstock = $this->input->post('f2');
$itemname = $this->input->post('f1');
$this->db->where('ItemName', $itemname);
$this->db->set('Stock', 'Stock-'.[$newstock], FALSE);
我收到此错误:
Severity: Notice
Message: Array to string conversion
Filename: models/inventory.php
最佳答案
找到一个解决方案:
$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);
谢谢你们的帮助。
关于php - 从数据库中减去PHP变量,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/22216836/