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 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题