Left Join Using PHP Mysqli

<table class="table datatable">
                                        <thead>
                                            <tr>
                                                <th>Sr. No</th>
                                                <th>Product Id</th>
                                                <th>Product Name</th>
                                                <th>Total Quantity</th>
                                                <!-- <th>Posted By</th>
                                                <th>Department</th> -->
                                                <th>Rrenaming Quantity</th>
                                               
                                               
                                            </tr>
                                        </thead>
                                       
                                        <tbody>
                                        <?php
                                           
                                            $count=0;
                                         $query="SELECT vg.product_id as pr, vg.product_name as pr_name, SUM(  `quantity` ) AS qun, f.Amount, f.product_id, f.product_name
FROM tbl_distributor_po vg
LEFT JOIN (

SELECT f.product_id, f.product_name, SUM(  `quantity` ) AS Amount
FROM tbl_dealer_po f
GROUP BY f.product_id
)f ON f.product_id = vg.product_id
WHERE vg.vname='".$_SESSION['distributor_name']."' and  `creation_timestamp` <= NOW( ) 
GROUP BY vg.product_name
";
                                             $row=mysqli_query($con,$query) or die(mysqli_error($con));
                                           
                                            while($fetch=mysqli_fetch_array($row)) {
                                                // extract($fetch);
                                        $a=$fetch['qun']-$fetch['Amount'];
                                               //$a1=$fetch['pr'];
                                        ?>
                                      

                                            <tr>
                                                <td><?php echo ++$count; ?></td>
                                                <td><?php echo $fetch
                                                ['pr'];?></td>
                                                <td><?php echo $fetch['pr_name'] ?></td>
                                                <td><?php echo $fetch['qun'] ?></td>
                                              
                                                <td><?php echo $a; ?></td>
                                               
                                            </tr>
                                            <?php } ?>
                                        </tbody>
                                    </table>
Previous
Next Post »