简体   繁体   English

我想按类别在两个不同的列中显示记录

[英]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_receiptcash_payment And also I have One more Voucher_type column in my table in this I have two type credit and debit . 而且我的表中还有一个Voucher_type列,其中我有两种类型的creditdebit 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.

相关问题 我想减去两个不同表的 2 列 - I want to subtract 2 columns of two different tables 两个表一个包含记录,第二个包含位置我想显示第一个表记录而不连接 - Two tables one contain records and second conatain location i want to show first table record with out join 想比较laravel中不同表的两列 - Want to compare two columns of different table in laravel 我想选择两个日期之间的记录 - I want to select record between two dates WordPress的投资组合显示所有项目,但我希望它显示按类别 - Wordpress Portfolio showing all items but i want it to show as per the category SQL 问题:我想显示与每个类别相关的结果 - SQL issue : I want to show results related to each category 要显示两个表中所附图像中提到的记录 - Want to show the record as mentioned in attached image from two tables 我想从redux框架中选择两个类别,但是它调用了一个 - I want to select two category from redux framework but it calls one 想要在magento中显示子类别 - Want to show sub category in magento 我正在使用Owl Carousel-按类别对项目进行筛选,因此我想在每个类别按钮单击时显示类别说明 - I am using Owl Carousel - Filter on projects as per category so i want to show the category description on every category button click
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM