我有这个问题,首先要获取学生总数,然后是 amount_paid 列中学生支付的总金额,我正在查询所有学生 id(system_id),然后是每笔付款,然后是发票和发票的成本费用目标是与学生匹配的 id。最后,我尝试减去循环中发送给选定学生的所有发票的总金额,然后从同一循环中发送给目标学生的费用中减去它。现在,我的许多问题是,对于第一批学生来说,它正在计算余额罚款,但其余的余额正在迅速增加。请问我的代码问题出在哪里:
<?php
$students = mysqli_query($conn, "SELECT * FROM students GROUP BY system_id");
while($row = mysqli_fetch_assoc($students)){
$user_uid = $row['system_id'];
$exam = $row['exam_number'];
//getting payments balances
//gettingshopping cart details
$Balance_query = mysqli_query($conn, "SELECT SUM(amount_paid) AS 'sumitem_cost' FROM payments WHERE payment_by='$user_uid' ");
$balance_data = mysqli_fetch_array($Balance_query);
$balance_price = $balance_data['sumitem_cost'];
$py = mysqli_query($conn, "SELECT * FROM payments WHERE payment_by='$user_uid' AND status!='rejected' GROUP BY invoice_id");
while($rowpy = mysqli_fetch_assoc($py)){
$paidAmout = $rowpy['amount'];
$invoiceId = mysqli_real_escape_string($conn, $rowpy['invoice_id']);
$PaymentStatus = mysqli_real_escape_string($conn, $rowpy['status']);
//Getting invoice
$Invoice = mysqli_query($conn, "SELECT * FROM invoices WHERE id='$invoiceId'");
while($rowInv = mysqli_fetch_assoc($Invoice)){
$NewFeeId = $rowInv['id'];
$sql = mysqli_query($conn,"SELECT SUM(fee) as total FROM invoices WHERE id='$invoiceId'");
$row = mysqli_fetch_array($sql);
$sum = $row['total'];
$total_price += $row[‘fee’];
}}
echo'<br>'.$exam.':' . $BalanceToPay = $total_price - $balance_price;
}
?>
跃然一笑
陪伴而非守候
ibeautiful