php - 我想按类别显示金额 贷方或借方 我只收到贷方金额
问题描述
我的表中有一个金额列,我想按信用或借记类别显示该金额,我只收到信用金额。
控制器
<?php foreach($modResult as $voucher):?>
<tr>
<th>Voucher No.</th>
<th>Voucher Amount BY CR.</th>
<th>Voucher Amount BY DR.</th>
<tr>
<tr>
<td><?php echo $voucher['voucher_no'];?></td>
<td><?php echo $voucher['voucher_amount'] = $voucher['voucher_transaction_type']=='CR' ? $voucher['voucher_amount'] : '';?></td>
<td><?php echo $voucher['voucher_amount'] = $voucher['voucher_transaction_type']=='DR' ? $voucher['voucher_amount'] : '';?></td>
</tr>
<?php endforeach; ?>
模型
$this->db->select('*');
$this->db->from('ts_voucher');
$this->db->where('voucher_category','cash_receipt');
$this->db->or_where('voucher_category','cash_payment');
$query=$this->db->get();
return $query->result_array();
如何在 Voucher Amount BY DR 列中显示 DR 值
解决方案
这样做
<td><?php echo $voucher['voucher_transaction_type'] == 'CR' ? $voucher['voucher_amount'] : '';?></td>
<td><?php echo $voucher['voucher_transaction_type'] == 'DR' ? $voucher['voucher_amount'] : '';?></td>
阅读更多条件运算符
推荐阅读
- python - 由于gevent导致heroku应用程序错误
- amazon-web-services - Connect to AWS Lighsail instance on port 9200 from AWS Lambda
- android - Publishing last tweet with twitter4j library - where exactly AsyncTask should be implemented?
- android - 使用android在SQLite数据库表中使用WHERE子句检索值
- c++ - What is zero overhead principle in C++? Examples?
- javascript - Negative Lookahead with multiple conditions
- javascript - Why am I not able to use fontawesome unicode icons on canvas?
- google-chrome - How to remove ssl certificates from the "trusted root certification authorities" under google chrome
- python - SqlAlchemy One-to-Many, only makes one-to-one
- javascript - How do I insert a background image using JavaScript