我如何添加代码字表中的所有列(表名钱箱)?我有这个代码和这张表。添加列codeigniter
SQL:
cash_id incoming outgoing
1 215.55 55.22
2 58.69 4.88
3 100 20
现在我需要从传入374.24和传出80,1共有,但我不为我的工作。
$data['cashbox'] = $this->db->query('SELECT SUM(incoming) FROM cashbox')->num_rows();
视图<?= $cashbox ?>
为什么如果你想总共使用'num_rows'。使用'result'并更改'$ data ['cashbox'] = $ this-> db-> select_sum('incoming') - > result();'。它会返回'array'所以'$ data ['cashbox'] [0]' – urfusion
嘿,谢谢你的回答。但我用这个代码得到这个“消息:调用未定义的方法CI_DB_mysqli_driver :: result()” –
你也可以使用'$ this-> db-> get();'。 '$ query = $ this-> db-> select_sum('incoming','incoming'); $ query = $ this-> db-> get('cashbox'); $ result = $ query-> result();' – urfusion