I am trying to build an e-commerce system but I can constraints, so when The purchase of goods then the database will reduce the field of stock, after I try, but the result does not fit, what's wrong?
Controllers
function purchase {
foreach($this->cart->contents() as $item)
{
$data = array(
'id_product' => $item['id'],
'name_product' => $item['name'],
'quatity' => $item['qty'],
'price' => $item['price'],
);
$data = array(
'stock' => -$item['qty']
);
$this->db->where('id_product', $item['id']);
$this->db->update('tbproduct', $data);
}
}
Did you try like this....
$items = $this->cart->contents();
function purchase {
foreach( $items as $item)
{
$stock=$item['stock']-$item['qty'];
$data = array(
'id_product' => $item['id'],
'name_product' => $item['name'],
'quatity' => $item['qty'],
'price' => $item['price'],
'stock' => $stock
);
$this->db->where('id_product', $item['id']);
$this->db->update('tbproduct', $data);
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.