[英]I want to show record in two different columns by category
I have one column voucher_category
in my table in this I have two (ENUM)
types of data cash_receipt
and cash_payment
. 我的表中有一列
voucher_category
,因为我有两种(ENUM)
类型的数据cash_receipt
和cash_payment
。 And also I have One more Voucher_type
column in my table in this I have two type credit
and debit
. 而且我的表中还有一个
Voucher_type
列,其中我有两种类型的credit
和debit
。 I want to show voucher_category
by Voucher_type
in two different column like following table 我想按
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
This is my code 这是我的代码
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();
}
This changes should work, depending on your code example: 根据您的代码示例,此更改应该起作用:
<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.