猿问

在1个数据库列中更新多个结果

尝试在1个数据库列中更新多个结果首先需要获取以前的值,而不是使用新的更新进行更新,到目前为止,我编写了此查询,但是它不起作用,请参见代码查询和当前结果


代码


<?php

include( $_SERVER['DOCUMENT_ROOT'] . '/config.php' ); $mysqli = $link;


  $user_pages = mysqli_query($mysqli,"SELECT actual_grand_total FROM user_pages"); 

  $actual_grand_total = $user_pages/100;

  $query1 = mysqli_query($mysqli,"update user_pages set actual_grand_total=($actual_grand_total)");

  $user_pages = mysqli_query($mysqli,"SELECT grand_total FROM user_pages"); 

  $grand_total = $user_pages/100;

  $query2 = mysqli_query($mysqli,"update user_pages set grand_total=($grand_total)");


?>

数据库表“ user_pages”


actual_grand_total | grand_total

------------------   -----------

       1000             750     

       5000             500     

       7500             750     

我得到那些错误的结果


    actual_grand_total | grand_total

    ------------------   -----------

           1.000             1.000     

           1.000             1.000     

           1.000             1.000  

预期成绩


 actual_grand_total | grand_total

    ------------------   -----------

           10             7.5     

           50             5     

           75             7.5     

有人可以纠正我吗...我想更新当前结果除以100


蝴蝶不菲
浏览 157回答 1
1回答

白衣非少年

您可以直接使用单个查询&nbsp; &nbsp;update user_pages&nbsp;&nbsp; &nbsp;set&nbsp; actual_grand_total = actual_grand_total/100 ,&nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; grand_total = grand_total/100&nbsp;
随时随地看视频慕课网APP
我要回答