简体   繁体   English

如何在PHP Codeigniter中从一个表中获取特定列,并从另一表中获取所有其他数据

[英]How to get specific column from one table and all other data from other table in php codeigniter

My problem is i want to print bill no,billdate,paty name,qty,amount,discount percentage,disc amount from purchase bill table along with i want to display item name according to the billno..how do i achieve this..i tried it with joining two table but it display the data repetitively.. Controller code: 我的问题是我想从购买账单表中打印出账单编号,账单日期,货品名称,数量,金额,折扣百分比,光盘金额以及我想根据账单号显示商品名称..我如何实现这一点..i尝试通过联接两个表来执行此操作,但它会重复显示数据。.控制器代码:

    if($name = $this->input->post('businessType'))
        {$this->db->where('date >=', $newDate);
        $this->db->where('date <=', $newDate2);
        $this->db->select('*');
        $this->db->from('purchasebill');
        $this->db->order_by("date", "asc");
        $this->db->join('purchasebill', 'purchasebill.date = purchaseitem.billdate','left outer');
        $this->db->join('parmaster','parmaster.Pcode = purchasebill.partyname','left outer');
  $query = $this->db->get()->result_array();
        $data['query'] = $query;

View code: 查看代码:

<th>Bill No</th>
                                    <th>Bill Date</th>
                                    <th>Party Name</th>
                                    <th>Item Name</th>
                                    <th>Qty</th>
                                    <th>Amount</th>
                                    <th>Disc %</th>
                                    <th>Disc Amt</th>
                                    <th>Bill Amount</th>
                                    <!--<th>Bill Amount</th>-->
                                </tr>

                            </thead>
                            <br>
                                                        <tbody>


                            <?php $rowcount = 1 ?>                          
                            <?php foreach($query as $row): ?>

                                    <tr>
                                        <td><?=$rowcount;?></td>
                                        <td><?=$row['no'];?></td>
                                        <td><?=$row['date'];?></td>
                                        <td><?=$row['PName'];?></td>
                                        <td><?=$row['Prdtname'];?></td>
                                        <td><?=$row['sqty'];?></td>
                                        <td><?=$row['billtot'];?></td>
                                        <td><?=$row['Disper'];?></td>
                                        <td><?=$row['Disamt'];?></td>
                                        <td><?=$row['Grdtot'];?></td>
                                        <?php $rowcount +=1?>
                                        <br>
                                        <?php endforeach ?> 

Help me to solve this problem...thanks in advance 帮我解决这个问题...谢谢

You are joining the same table on line no. 您将在第7行加入同一张表。 7, that's why its repeating. 7,这就是其重复的原因。 May be,you want to join 'purchaseitem' table. 可能是,您想加入“ purchaseitem”表。 If so,then change that line to this - 如果是这样,则将该行更改为此-

   $this->db->join('purchaseitem', 'purchasebill.date = purchaseitem.billdate','left outer');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM