gpt4 book ai didi

php - 从数据库中减去 PHP 变量

转载 作者:行者123 更新时间:2023-11-29 13:10:01 25 4
gpt4 key购买 nike

我正在使用 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com