gpt4 book ai didi

php - 总结特定学生支付的所有金额

转载 作者:行者123 更新时间:2023-11-29 05:20:00 26 4
gpt4 key购买 nike

我有一个表名:

Fee_payment
payment_id student_id name class_id term year amount creation_timestamp
1 7 john JHS2A second_term 20014 34 1416610800
2 5 Grace JHS2B second_term 20014 34 1416610856
3 6 john JHS2A second_term 20014 56 1416610800

如果用户点击费用记录,我想计算 john 支付的总金额。我只能获取当前支付的金额,但无法汇总学生支付的所有金额。

我正在寻找的是,如果例如 john 出现两次,我应该能够根据 term 和 creation_timestamp 将 john 支付的款项加在一起。

我尝试过的:

 <div class="box-content">
<?php foreach($edit_data as $row):?>


<div class="pull-left">

<span style="font-size:20px;font-weight:100;">

<?php echo get_phrase('payment_to');?>
<img width="50" height="30" src="<?php echo base_url();?>uploads/logo.png" style="max-height:100px;margin:20px 0px;" />
</span>
<br />
<?php echo $system_name;?>
<br />
<?php echo $this->db->get_where('settings' , array('type'=>'address'))->row()->description;?>
</div>
<div class="pull-right">
<span style="font-size:20px;font-weight:100;">
<?php echo get_phrase('credited_account:');?>
</span>
<br />
<?php echo $this->db->get_where('student' , array('student_id'=>$row['student_id']))->row()->name;?>
<br />
<?php echo get_phrase('student_id');?> :
<?php echo "FAVECSID0000", $this->db->get_where('student' , array('student_id'=>$row['student_id']))->row()->student_id;?>
<br />
<?php echo get_phrase('class');?> :
<?php
$class_id = $this->db->get_where('student' , array('student_id'=>$row['student_id']))->row()->class_id;
echo $this->db->get_where('class' , array('class_id'=>$class_id))->row()->name;
?>
</div>
<div style="clear:both;"></div>
<hr />
<table width="100%" background="http://localhost/schoolmanager/uploads/backlogos.png">
<tr style="background-color:#7087A3; color:#fff; padding:5px;">
<td style="padding:5px;"><?php echo get_phrase('payment_details');?></td>
<td width="30%" style="padding:5px;">
<div class="pull-right">
<?php echo get_phrase('amount');?>
</div>
</td>
</tr>
<tr>
<td>
<span style="font-size:20px;font-weight:100;">
<?php echo get_phrase('payment_made');?>
</span>
<br />

</td>
<td width="30%" style="padding:5px;">
<div class="pull-right">
<span style="font-size:20px;font-weight:100;">
<?php echo "Gh", $row['amount'];?>
</span>
</div>
</td>
</tr>

<tr>

<tr>
<td>
<span style="font-size:20px;font-weight:100;">
<?php echo get_phrase('balance');?>
</span>
<br />
<?php echo $row['description'];?>
<?php
$exams = $this->db->get_where('fee_payment', array('student_id'=>$row['student_id']))->result_array();
foreach($exams as $row):
?>
<?php

$ttpaid = sum($row['amount']);
echo $ttpaid;?>
<?php
endforeach;
?>
</td>
<td width="30%" style="padding:5px;">
<div class="pull-right">
<span style="font-size:20px;font-weight:100;">
<?php

$tuition = $this->db->get_where('student' , array('student_id'=>$row['student_id']))->row()->tuition_fee;
$status = $this->db->get_where('student' , array('student_id'=>$row['student_id']))->row()->status_fee;
$total_fees = $tuition + $status;
$balance_fee = $total_fees - $row['amount'];
echo "Gh", $balance_fee;
?>
</span>
</div>
</td>
</tr>

<tr>

<td></td>
<td width="30%" style="padding:5px;">
<div class="pull-right">
<hr />
<?php echo get_phrase('status');?> : <?php echo $row['status'];?>
<br />
<?php echo get_phrase('receipt_no:');?> : <?php echo "FAVECSFP0000",$row['payment_id'];?>
<br />
<?php echo get_phrase('date');?> : <?php echo date('m/d/Y', $row['creation_timestamp']);?>
</div>
</td>
</tr>
</table>
<br />
<br />


<?php endforeach;?>
</div>
</div>

输出:

Payment To
FAIRVIEW EDUCATIONAL CENTER
P O BOX 126
Credited Account:
john
Student Id : FAVECSID00007
Class : JHS2A
Payment Details
Amount
Payment Made Gh34
Balance

最佳答案

MySQL 的好处在于它不像一张真正的纸,没有理由将自己限制在一个表上。在这种情况下,您有 Fee_payment 表,但似乎最好添加第二个表,例如 Students

在那种情况下,您可能有一个如下所示的表格:

Students
id name account_created
1 John 1416610800
2 Grace 1416609200

所以在您的Fee_payment 表中,您不再需要存储学生的姓名。您只需使用 student_id 列来引用 Students 表中的 id 列。然后,当 John 登录时(或者有人根据 Students 表中存在的行查找 John),您需要做的就是搜索 Fee_payment 表对于匹配 John 的 student_id

在这种情况下,查询将类似于:

SELECT sum(amount) FROM Fee_payment WHERE student_id = 1

这将返回 John 支付的总金额,并为您提供您正在寻找的内容。

关于php - 总结特定学生支付的所有金额,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27193358/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com