好吧,如果客户支付他每月运行的账单,我会将数据插入client_pay_bill
表。
所以,例如;
今天是2016-08-29。
如果客户账单为700
而且他支付的费用超过了他的每月账单,例如1800
,那么我想将此1800 / 700
分开。因此,pay_amount
,bill_month
和due_amount
列数据将按以下方式插入3次:
表:clients_pay_bill
pay_amount bill_month due_amount
=======================================
700 2016-08-29 0
700 2016-09-29 0
400 2016-10-29 0
否则如果他只支付每月帐单700
或更少,那么700
我想要运行我的else
语句。
因此,我无法确定查询的外观。贝娄是我的代码(未完成)
$entry_date = time();
if($advance_amount > $monthly_bill) {
$counting_month = round($advance_amount / $monthly_bill);
$advance_amount .= $ad;
for ($x=0; $x<=$counting_month; $x++) {
$r = $advance_amount - $monthly_bill;
$ad = $r;
$insert_to_month = mysqli_query($conn, "INSERT INTO
clients_pay_bill (client_id, pay_amount, bill_month, receipt_no,
entry_date, uid, remark) VALUES('$client_id', '', '', '', '', '',
'' ) ");
}
} else {
$insert = mysqli_query($conn, "INSERT INTO clients_pay_bill (client_id,
pay_amount, discount_amount, due_amount, advance_amount, bill_month,
receipt_no, entry_date, is_paid, uid, remark) VALUES('$client_id',
'$paid_amount', '$discount_amount', '$due_amount', '$advance_amount',
'$bill_month', '$receipt_no', '$entry_date', '1', '$uid', '$remark' )
");
}
答案 0 :(得分:0)
试试这个
$entry_date = date("Y-m-d");
if($advance_amount > $monthly_bill) {
$counting_month = round($advance_amount / $monthly_bill);
$advance_amount .= $ad;
for ($x=0; $x<=$counting_month; $x++) { //This loop will run for 700 700
$r = $advance_amount - $monthly_bill;
$ad = $r;
$forOdNextMonth= date('m', strtotime("+".$x." month", strtotime($entry_date )));
$insert_to_month = mysqli_query($conn, "INSERT INTO
clients_pay_bill (client_id, pay_amount, bill_month, receipt_no,
entry_date, uid, remark) VALUES('$client_id', '$monthly_bill;', '$forOdNextMonth', '$receipt_no', '$entry_date', '$uid', '$remark' ) ");
}if($r>0){ //This loop will run for remaining amount 400 as amount will be 1800
$forOdNextMonth= date('m', strtotime("+".($x+1)." month", strtotime($entry_date )));
$insert_to_month = mysqli_query($conn, "INSERT INTO
clients_pay_bill (client_id, pay_amount, bill_month, receipt_no,
entry_date, uid, remark) VALUES('$client_id', '$r', '$forOdNextMonth', '$receipt_no', '$entry_date', '$uid', '$remark' ) ");
}
} else {
$insert = mysqli_query($conn, "INSERT INTO clients_pay_bill (client_id,
pay_amount, discount_amount, due_amount, advance_amount, bill_month,
receipt_no, entry_date, is_paid, uid, remark) VALUES('$client_id',
'$paid_amount', '$discount_amount', '$due_amount', '$advance_amount',
'$bill_month', '$receipt_no', '$entry_date', '1', '$uid', '$remark' )
");
}
关于分钱的TESTCODE
<?php
$amount=1800;
$monthlybill=700;
for($i=0;$i<$amount/$monthlybill;$i++)
{
echo"paid for ".($i+1)." month =".$monthlybill."<br>";
$amount-=$monthlybill;
}
if($amount>0){
echo"paid for ".($i+1)." month =".$amount;
}
?>