【问题标题】:How to get specific column from one table and all other data from other table in php codeigniter如何从一个表中获取特定列以及从 php codeigniter 中的另一个表中获取所有其他数据
【发布时间】:2018-10-30 10:03:23
【问题描述】:

我的问题是我想打印账单编号、账单日期、付款人名称、数量、金额、折扣百分比、购买账单表中的光盘金额以及我想根据账单显示项目名称..我如何实现这一点..我尝试加入两个表,但它重复显示数据.. 控制器代码:

    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;

查看代码:

<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 ?> 

帮我解决这个问题...在此先感谢

【问题讨论】:

    标签: php codeigniter


    【解决方案1】:

    您将在第 1 行加入同一张桌子。 7,这就是它重复的原因。可能是,您想加入“purchaseitem”表。如果是这样,则将该行更改为 -

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

    【讨论】:

    • 我试过了,但我得到的不是唯一的表数据库错误
    • 那么您使用的主键和外键可能不是唯一的,或者在加入表中有许多相似的行。尝试使用唯一的id 而不是日期或名称。喜欢 - $this-&gt;db-&gt;join('purchaseitem', 'purchasebill.item_id=purchaseitem.id','left outer'); $this-&gt;db-&gt;join('parmaster','parmaster.id=purchasebill.parmaster_id','left outer'); 注意:为此,您必须在插入时将 purchaseitemid 插入到 purchasebillitem_id 中。类似地,idparmaster 插入到 @ 987654331@根据采购单的项目和参数。
    猜你喜欢
    • 1970-01-01
    • 2020-12-04
    • 1970-01-01
    • 1970-01-01
    • 2021-10-19
    • 1970-01-01
    • 2017-01-14
    • 1970-01-01
    • 2019-05-02
    相关资源
    最近更新 更多