[英]I want to show record in two different columns by category
我的表中有一列voucher_category
,因為我有兩種(ENUM)
類型的數據cash_receipt
和cash_payment
。 而且我的表中還有一個Voucher_type
列,其中我有兩種類型的credit
和debit
。 我想按Voucher_type
在兩個不同的列中顯示voucher_category
,如下表
I want this type of columns
Voucher No Voucher_Category_By_Credit Voucher_Category_By_Debit
1 cash payment
2 cash receipt
Currently I'am receiving like this bellow
Voucher No Voucher_Category voucher_category_type
1 cash payment credit
2 cash receipt debit
這是我的代碼
Controller
$modResult = $this->sendValues->receiving($data);
<tr>
<th>Voucher No.</th>
<th>Voucher_Category</th>
<th>voucher_category_type</th>
</tr>
<?php foreach($modResult as $voucher):?>
<tr>
<td><?php echo $voucher['voucher_no'];?></td>
<td><?php echo $voucher['voucher_category'];?></td>
<td><?php echo $voucher['voucher_category_type'];?></td>
</tr>
<?php endforeach; ?>
model
public function receiving($data){
extract($data);
$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();
}
根據您的代碼示例,此更改應該起作用:
<tr>
<th>Voucher No</th>
<th>Voucher_Category_By_Credit</th>
<th>Voucher_Category_By_Debit</th>
</tr>
<?php foreach($modResult as $voucher):?>
<tr>
<td><?php echo $voucher['voucher_no'];?></td>
<td><?php echo $voucher['voucher_category_type']=='credit' ? $voucher['voucher_category'] : '';?></td>
<td><?php echo $voucher['voucher_category_type']=='debit' ? $voucher['voucher_category'] : '';?></td>
</tr>
<?php endforeach; ?>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.