我试图从这个循环得到小计,但没有得到

时间:2017-07-01 08:24:19

标签: php mysql codeigniter

enter image description here我的模特

public function get_dat($start_date, $end_date) {

       $this->db->select('*');
       $this->db->from('jil_mroproducts');


       $query = $this->db->get();
       if ($query->num_rows() > 0) {
            $sum=0;
            foreach ($query->result() as $row) {
                $this->db->select('*,sum(pocd_sellingprice) as gg');
                $this->db->from('jil_jikwarehouse');
                $this->db->join('jil_pojmdetail', 'jil_pojmdetail.pojd_id=' . $this->table4 . '.ware_poid', 'left');
                $this->db->join('jil_pocjdetail', 'jil_pocjdetail.pocd_qumjid=jil_pojmdetail.pojd_qumjid', 'left');
                $this->db->join('jil_users', 'jil_users.usr_id=jil_pojmdetail.pojd_customerid', 'left');
                $this->db->group_by('jil_jikwarehouse.ware_productid');
                $this->db->where('jil_jikwarehouse.ware_productid', $row->mro_id);
                $this->db->where('jil_jikwarehouse.ware_time >=', $start_date);
                $this->db->where('jil_jikwarehouse.ware_time <=', $end_date);
                $query1 = $this->db->get();
                if ($query1->num_rows() > 0) {
                    $data[] = $row;
                }

                foreach ($query1->result() as $row) {

                   $sum+=$row->pocd_sellingprice;

                   $data[] = $row;
                }
                $data[]['subtotal']=$sum;// here am trying to get subtotal
            }


            return $data;
        }
        return false;
    }

查看

 <table style="width: 100%">
            <tr>
                 <th style="width: 5px">PO ID</th>
                 <th style="width: 5px">PO Dated</th>
                 <th style="width: 50px">PO Quantity</th> 
                 <th style="width: 10px">Purchase Value</th>
                 <th style="width: 10px">Available Stock</th>
                 <th style="width: 5px">PO Customer ID</th>
                 <th style="width: 5px">PO Dated</th>
                 <th style="width: 50px">PO Quantity</th> 
                 <th style="width: 10px">Sale Value</th>
            </tr>

 <?php
            $slno = 0;
            $pur=0;
            $sel=0;

            if (!empty($list)) {
                foreach ($list as $user_fetcheach) {
                    ?>
                    <tr><td colspan="6" style="text-align:left;"><?php echo '<h4>' . $user_fetcheach->mro_name . '</h4>'; ?></td></tr>
                    <?php if (!empty($user_fetcheach->ware_id)) {


                        $pur+=$user_fetcheach->pojd_sellingprice;
                        $sel+=$user_fetcheach->pocd_sellingprice;
                        $slno++; ?>
                        <tr>


                             <td><?php echo $user_fetcheach->ware_pomainid.'-'.$user_fetcheach->ware_poid; ?></td>
                            <td><?php echo date('d-m-Y',$user_fetcheach->pojd_dated); ?></td>
                            <td><?php echo $user_fetcheach->pojd_quantity; ?></td>
                            <td><?php echo $user_fetcheach->pojd_sellingprice; ?></td>
                            <td><?php echo $user_fetcheach->ware_quantity; ?></td>
                          <td><?php echo $user_fetcheach->pocd_id.'-'.$user_fetcheach->pocd_pocjid; ?></td>
                            <td><?php  echo date('d-m-Y',$user_fetcheach->pocd_dated); ?></td>
                            <td><?php echo $user_fetcheach->pocd_quantity; ?></td>
                            <td><?php echo $user_fetcheach->pocd_sellingprice; ?></td>

                        </tr>

                    <?php } ?>

                    <?php
                }
            }

            ?>
                            <tr><td><b>Grand Total:-</b></td><td></td><td></td><td><?php echo $pur;?></td><td></td><td></td><td></td><td></td><td><?php echo $sel;?></td></tr>
        </table>[![enter image description here][1]][1]

目前我正在获得这样的观点,我试图在标记的地方显示每个产品的小计但没有得到,请帮助,如果有人可以提供帮助。 我根据每个产品得到每一行,也显示总计。请帮我显示每个产品的小计

0 个答案:

没有答案