dputlf5431 2018-03-25 08:55
浏览 44
已采纳

在不使用codeigniter中的查询构建器的情况下总计总计

I would like to find total outstanding arrears for each doctor and display the result.

my controller

public function pay_salaries()
{ 
$salary['salaries'] = $this->db->query("SELECT * FROM salaries WHERE Payment_status IS NULL ORDER BY Salary_id DESC")->result_array();

$this->load->view('backend/admin/pay_salaries',$salary);
}

This controller really does so well until I want to echo all arrears for a doctor

view

    <thead>
        <tr>
            <th>DOCTOR'S NAME</th>
            <th>TOTAL PENDING AMOUNT</th>
        </tr>
    </thead>
    <tbody>
<?php foreach ($salaries as $salary): 

$doctor_id = $salary['doctor_id'];

$doctor_name = $this->db->query("SELECT * FROM user_details,doctors WHERE Doctor_id='$doctor_id' AND User_details_User_id=User_id")->row_array();

   $total_outstanding_amount = $this->db->query("SELECT SUM(Amount) AS Arrears FROM salaries WHERE Payment_status IS NULL AND doctor_id = '$doctor_id'")->result_array();
?>
    <tr>
            <td><?php echo $doctor_name['Fname'].' '.$doctor_name['Sname']; ?></td>
            <td><?php echo $total_outstanding_amount['Arrears']; ?></td>

        </tr>
<?php endforeach ?>   
    </tbody>

my database is like this enter image description here

total i expect in Arrears should be 5500+500 = 6000

I can't figure this out in a day. Please help... Thanks in advance

The error I keep getting is

Severity: Notice

Message: Undefined index: Arrears

Filename: admin/pay_salaries.php

Line Number: 79

Backtrace:

File: C:\wamp64\www\Alphadoctors\application\views\backend\admin\pay_salaries.php
Line: 79
Function: _error_handler
  • 写回答

1条回答 默认 最新

  • duanchandun1860 2018-03-25 09:23
    关注

    This should help you, as i could not figure out what you doing in your code.

    so what you can do is set a var $sum = 0; outside the foreach loop. then you can try

    foreach ($sql['Amount_CHANGEME'] as $key => $value)
    {
        $sum += $value
        echo $sum; //should display 6000
    }
    

    is this offset correct? $total_outstanding_amount['Arrears'] as i do not see it in the phpmyadmin table

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?