使用php mysqli创建分类帐并根据DR和CR获得余额 [英] using php mysqli create ledger book and get balance as per DR and CR

查看:89
本文介绍了使用php mysqli创建分类帐并根据DR和CR获得余额的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在管理区域中创建了一个PHP分类帐系统,用于管理客户帐户金额.

I have created a PHP ledger book system in the admin area to manage clients accounts amount.

我已经在phpmyadmin中创建了下表:

I have created the below table in phpmyadmin:

我尝试使用以下代码获取结果:

I have tried using the below code for getting the result:

$list_balance = mysqli_query($con_db,"SELECT * FROM tbl_balancesheet where client_id='".$_GET['cid']."' ORDER by id desc" );
$total = 0;
while($row = mysqli_fetch_array($list_balance)){
if($row['action_type']=='dr'){
    $debit = $row['amount'];
    $total += $row['amount'];
}else{
    $credit = $row['amount'];
    $total -= $row['amount']; 
}
<tr>
    <td><?php echo $row['created_date']; ?></td>
    <td><?php echo $row['particular']; ?></td>
    <td>
    <?php 
        if($row['action_type']=='dr'){ 
            echo $debit;
        }else{
            echo ' ';       
        }
    ?>
    </td>
    <td>
    <?php 
        if($row['action_type']=='cr'){ 
            echo $credit;
        }else{
            echo ' ';       
        }
    ?>
    </td>
    <td><?php echo $total; ?></td>
</tr>

我得到以下结果,但是我不想在余额前面显示减号(-)图标:

I am getting the below result, but I don't want to show a minus (-) icon in front of balance:

此外,我想显示最后一个条目,但结果显示不正确.

Also, I want to display the last entry in first but the result is not displaying correctly.

预期结果应如下所示

请帮助我如何获得上述结果.另外,如何显示dr和cr.

Please help me how I can get the above result. Also, how I can display the dr and cr.

示例::如果管理员仅向客户 400 要钱.但是有些时候,客户已经向管理员支付了预付款,然后客户从管理员那里借钱.在这种情况下,有时管理员会从客户那里获得一定数量的博士,而有时会从管理员那里获得客户博士的数量.

Ex: If the admin asks money from customers 400 only. But some times customers had paid an advance amount to admin then the customer borrow money from admin. In that case, some times admin amount dr form customers and some times customers dr from admin.

谢谢

推荐答案

我不想在余额前面显示减号(-)图标:

I don't want to show a minus (-) icon in front of balance:

您应该使用 abs 函数:

<td><?php echo abs($total); ?></td>

此外,我想显示最后一个条目,但结果显示不正确.

Also, I want to display the last entry in first but the result is not displaying correctly.

在代码中,在sql查询中,您具有ORDER by id desc,这表示按ID降序 (最后插入的条目排在最前面) 如果要将顺序更改为,请从查询中删除desc.

In the code, in the sql query you have ORDER by id desc which means descending order by id (last inserted entry goes first) If you want to change the order to ascending then remove desc from the query.

这篇关于使用php mysqli创建分类帐并根据DR和CR获得余额的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆