简体   繁体   English

如何从php和mysql的总和中减去总和

[英]How to MINUS sum of values from sum of values php and mysql

am very new in php, and I have serious question to get the answer, I hope you will help me. 在php中非常新,我有一个很严肃的问题要得到答案,希望您能对我有所帮助。

I have a table on mysql named "Payment" with the following fields 我在mysql上有一个名为“ Payment”的表,其中包含以下字段

(School_fee  |  Fee_setting  |  Trans_port  |   trans_setting)

in fields setting of all fields i set the actual total amount of money which student suppose to pay for appropriate service per 3 month, and student can pay for installment, So guys I want when I set may be 100000 at once in fee_setting, and when student come and pay 20000 as School_fee the amount will be reducted each time when student pay a school_fee . 在所有字段的字段设置中,我设置了学生应该每3个月为适当服务支付的实际总金额,并且学生可以分期付款。因此,当我设置费用时,我想要的人可能一次是100000,学生来支付20000作为School_fee,每次学生支付school_fee都会减少金额。 this means (fee_setting) it will reduct total number of school_fee payed by a certain student. 这意味着(fee_setting)将减少某个学生支付的school_fee总数。

I have the codes but this reduct only first student and others student the results comes with negative sign(-), Am confused i don't know where the problems is. 我有代码,但这仅减少了第一名学生和其他学生的成绩,结果带有负号(-),我很困惑,我不知道问题出在哪里。

Here the codes: 这里的代码:

echo $results['SUM(fee_setting)'] - $results ['SUM(school_fee)']."</td>";   

我认为您需要abs()来避免出现负值:

echo abs($results['SUM(fee_setting)'] - $results ['SUM(school_fee)'])."</td>";   

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM