我是编程新手,我遇到了Mysql更新代码的问题。我在'100m'列中有4个不同的行值,我尝试使用While循环为每个不同的行计算$ points1,然后计算它,并根据行值更新表。但是从第4行开始,第3个获得Total_score更新。Mysql php更新在while循环中不起作用
表:
表结构:
代码:
<?php
include ("config.php");
$sql= "SELECT * FROM data_from_file";
$result= $db->query($sql);
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()){
$P=$row['100m'];
$A=25.4347;
$B=18;
$C=1.81;
$points1 = $A*(($B-$P)**$C);
$insert =$db->query("UPDATE data_from_file SET Total_score=$points1 WHERE 100m=$P");
echo $P;
echo "<br>";
echo $points1;
echo "<br>";
};
}
?>
为什么只是第三个更新?
我使用Exponentiation运算符,所以我可以更改$ points1 = $ A *(($ B- B- $ P)** $ C); –
@Lukas Abromas你说得对。 – jetblack