使用计数器变量获取列中的下一个值,而SQL中没有任何数组?

时间:2015-09-15 06:56:49

标签: php sql select

我想使用变量移动到列的下一行。就像我有一个专栏$dr。现在,当我对balance的第一个值进行计算时,我想转到列中的下一个值,然后在那里执行一些计算,然后到第三个,依此类推。

算法

  1. 从用户处获取$debited_amount的值。
  2. 从表格$dr中选择$payment
  3. 计算$debited_amount = gp_no - $debited_amount。可能有三种情况。
      

    a)gp_no< 0 //当用户支付更多金额时,他需要支付$debited_amount = 1

         
        

    b)gp_no> 0)//当用户支付较少的金额时,他需要支付balance = 1

             
          

    c)$dr = 0 //当用户支付与他需要支付的balance = 1

    相同的金额时     
      
  4. 如果(c),则通过为第一组设置$dr = 0并退出来更新$debited_amount;
  5. 如果(b),则通过为第一组设置balance = $dr并退出来更新0;
  6. 如果(a),则通过为第一个组设置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;
  7. 以下是PHP代码:

    {{1}}

0 个答案:

没有答案