我想使用变量移动到列的下一行。就像我有一个专栏$dr
。现在,当我对balance
的第一个值进行计算时,我想转到列中的下一个值,然后在那里执行一些计算,然后到第三个,依此类推。
算法
$debited_amount
的值。$dr
中选择$payment
。$debited_amount
= gp_no
- $debited_amount
。可能有三种情况。
a)
gp_no
< 0 //当用户支付更多金额时,他需要支付$debited_amount
= 1b)
gp_no
> 0)//当用户支付较少的金额时,他需要支付balance
= 1c)
相同的金额时$dr
= 0 //当用户支付与他需要支付的balance
= 1
$dr
= 0并退出来更新$debited_amount
; balance
= $dr
并退出来更新0
; dr
= <?php
If(isset($_REQUEST['submit'])!='')
{
$member_no = $_REQUEST['member_no'];
$payment = $_REQUEST['payment'];
$sql = "create view balance as select gp_no,sum(dr) as dr from instalment WHERE member_no = '$member_no' group by gp_no" ;
$sql = "select * from balance";
$result = mysqli_query($conn, $sql);
if (mysqli_num_rows($result) > 0)
{
while($row = mysqli_fetch_assoc($result))
{
$dr = $row["dr"];
}
}
$debited_amount = $dr - $payment ;
$payment = $payment - $dr;
$i = 1 ;
do
{
if ($debited_amount < 0 ) // when the user pays more amount as he needs to pay for gp_no = 1
{
$sql = "update balance set dr = 0 WHERE gp_no = '$i' " ;// dr will be updated by dr = 0;
$dr++; // and move to next dr for subratraction i.e., dr of gp_no = 2
$i++;
$debited_amount = $dr - $payment ;
$payment = $payment - $debited_amount ;
}
elseif ($debited_amount > 0) // when the user pays less amount as he needs to pay for gp_no = 1
{
$sql = "update balance set dr = $debited_amount WHERE gp_no = '$i' " ;// dr will be updated by dr = $debited_amount ;
$dr = $debited_amount ;
$payment = $payment + $debited_amount ;
}
else // when the user pays exactly the same amount as he needs to pay for gp_no = 1
{
$sql = "update balance set dr = 0 WHERE gp_no = '$i' " ;// dr will be updated by dr = 0;
$dr = 0;
}
} while ($payment !=0 );
来更新{{1}},并为下一个组选择{{1}}并转到步骤3; 以下是PHP代码:
{{1}}