简体   繁体   中英

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:

    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, that's why its repeating. May be,you want to join 'purchaseitem' table. If so,then change that line to this -

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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