在1个数据库列中更新多个结果
问题描述:
Trying to update multiple results in 1 database column first need to get previous values than update with new so far i wrote this query but it's not working see code query & current results
Code
<?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)");
?>
database table "user_pages"
actual_grand_total | grand_total
------------------ -----------
1000 750
5000 500
7500 750
I am getting those wrong results
actual_grand_total | grand_total
------------------ -----------
1.000 1.000
1.000 1.000
1.000 1.000
expected results
actual_grand_total | grand_total
------------------ -----------
10 7.5
50 5
75 7.5
can someone correct me ... i want to update current results dividing by 100
尝试更新1个数据库列中的多个结果首先需要获取以前的值而不是使用new更新到目前为止我写了这个 查询,但它不工作,请参阅代码查询&amp; 当前结果 p>
代码 p>
&lt;?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)”);
?&gt;
code> pre>
数据库表“user_pages” p>
actual_grand_total | grand_total
------------------ -----------
1000 750
5000 500
7500 750
code> pre>
我得到了错误的结果 p>
blockquote>
actual_grand_total | grand_total
------------------ -----------
1.000 1.000
1.000 1.000
1.000 1.000
code> pre>
预期结果 p>
blockquote>
actual_grand_total | grand_total
------------------ -----------
10 7.5
50 5
75 7.5
code> pre>
有人可以纠正我...我想更新当前结果除以100 p>
div>
答
you could do directly and using a single query
update user_pages
set actual_grand_total = actual_grand_total/100 ,
grand_total = grand_total/100