Codeigniter-如何对表的两列求和并显示

时间:2019-02-17 16:40:05

标签: codeigniter-3

如何使用函数计算mysql表的两列之和?如下

在“订单”列2的两个列中添加值,在列1“小计”的列2“描述”中如何将两列求和?

公共函数count_gainliquid(){// Ganho Liquido

    $this->ci->db->where('status', '1');

    $count = $this->ci->db->get('orders');

    $processbar = (1000 * $count->num_rows());

    $total = 0;

    foreach ($count->result() as $row) {

            $this->ci->db->where('id', $row->id);

            $orders = $this->ci->db->get('orders');

            if ($orders->num_rows() > 0) {

                foreach ($orders->result() as $ord) {

                    $total += $ord->subtotal;

                }

            }

        }



    return json_decode(json_encode(array('processbar' => $processbar, 'count' => $count->num_rows(), 'total' => number_format($total, 2, ",", ".") )));

    }

0 个答案:

没有答案