<?php
require_once "config.php";
$sql = "SELECT * FROM charges";
$results = mysqli_query($link, $sql);
$row = mysqli_fetch_array($results);
$count = mysqli_num_rows($results);
for ($i=0; $i <=$count ; $i++) {
$id = $row['c_id'];
$newBalance = $row['charge']+$row['balance'];
$query = "UPDATE charges SET balance = $newBalance WHERE c_id = $id";
mysqli_query($link, $query)
}
?>
那是我的PHP代码
下图是我的数据库表
database table
最佳答案
您的查询是:
UPDATE charges SET balance = balance + charge
与PHP的是:
$sql = "UPDATE charges SET balance = balance + charge";
$results = mysqli_query($link, $sql);
关于php - 我想添加费用和余额记录,并将其更新到其他列或同一余额列,但是仅第一个记录受到影响,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/49352152/