要减少库存,可以使用以下代码:
// 假设库存数量存储在名为"inventory"的表中
$query = "SELECT quantity FROM inventory WHERE product_id = :product_id";
$stmt = $pdo->prepare($query);
$stmt->bindParam(':product_id', $product_id);
$stmt->execute();
$row = $stmt->fetch(PDO::FETCH_ASSOC); $current_quantity = $row['quantity'];
2. 然后,减少库存数量:
```php
$new_quantity = $current_quantity - $decrease_amount;
// 更新库存数量
$query = "UPDATE inventory SET quantity = :new_quantity WHERE product_id = :product_id";
$stmt = $pdo->prepare($query);
$stmt->bindParam(':new_quantity', $new_quantity);
$stmt->bindParam(':product_id', $product_id);
$stmt->execute();
以上代码假设你已经建立了与数据库的连接,并且使用了PDO来执行数据库查询和更新操作。你需要根据实际情况修改代码中的表名、列名和变量名。
上一篇:php二级栏目遍历
Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3
Laravel 中文站