我的表格中只有一个金额列,我想按贷项或借项类别显示该金额,我只会收到贷项金额。

控制者

 <?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();


如何在“凭凭证的借项金额”列中显示借项值

最佳答案

像这样

<td><?php echo $voucher['voucher_transaction_type'] == 'CR' ? $voucher['voucher_amount'] : '';?></td>

 <td><?php echo $voucher['voucher_transaction_type'] == 'DR' ? $voucher['voucher_amount'] : '';?></td>


阅读更多conditional operators

关于php - 我想按贷项或借项类别显示金额我只收到贷项金额,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/54457934/

10-12 22:24