如何在Codeigniter中打印关联数组

时间:2018-11-20 09:22:35

标签: arrays codeigniter

我的控制器是: **

public function getdatewiseOrder()
        {


                $cid        = $this->input->post('cid');
                $startdate  = strtotime($this->input->post('start_date'));
                $enddate    = strtotime($this->input->post('end_date'));

                $order = $this->model_reports->getdatewiseOrder($cid, $startdate, $enddate);
                $x = 0;
                foreach ($order as $key => $value) {
                    $item[$x] = $this->model_reports->getorderItem($value['id']);
                    $x = $x + 1;

                }



                $this->data['order']    = $order;
                $this->data['item']     = $item; 

                $this->render_template('reports/leser_report', $this->data);
        }

检查:在项目变量的print_r之后,我以以下格式获取数据:

Array ( 
    [0] => Array ( 
        [0] => Array ( 
            [id] => 188 
            [order_id] => 93 
            [product_name] => 2 
            [barcode_nos] => 
            [barcode_no] => 
            [qtykg] => 1 
            [qtypcs] => 2 
            [unit] => 
            [rate] => 234 
            [amount] => 234.00 
            [tax_id] => 
            [timestamp] => 2018-10-30 12:51:10 
        ) 
    ) 
    [1] => Array ( 
        [0] => Array ( 
            [id] => 191 
            [order_id] => 96 
            [product_name] => Small 
            [barcode_nos] => 
            [barcode_no] => 
            [qtykg] => 5 
            [qtypcs] => 5 
            [unit] => 
            [rate] => 100 
            [amount] => 500.00 
            [tax_id] => 
            [timestamp] => 2018-11-15 09:49:41 
        ) 
        [1] => Array ( 
            [id] => 192 
            [order_id] => 96 
            [product_name] => Medium 
            [barcode_nos] => 
            [barcode_no] => 
            [qtykg] => 5 
            [qtypcs] => 5 
            [unit] => 
            [rate] => 90 
            [amount] => 450.00 
            [tax_id] => 
            [timestamp] => 2018-11-15 09:49:43 
        ) 

    ) 
    [2] => Array ( 
        [0] => Array ( 
            [id] => 206 
            [order_id] => 105 
            [product_name] => Small 
            [barcode_nos] => 
            [barcode_no] => 
            [qtykg] => 2 
            [qtypcs] => 50 
            [unit] => 
            [rate] => 100 
            [amount] => 200.00 
            [tax_id] => 
            [timestamp] => 2018-11-15 13:38:47 
        ) 
    ) 
    [3] => Array ( 
        [0] => Array ( 
            [id] => 207 
            [order_id] => 106 
            [product_name] => Medium 
            [barcode_nos] => 
            [barcode_no] => 
            [qtykg] => 50 
            [qtypcs] => 100 
            [unit] => 
            [rate] => 15 
            [amount] => 750.00 
            [tax_id] => 
            [timestamp] => 2018-11-15 13:40:12 
        ) 
    ) 
)

我有两个表order和order_item,我从这两个表中获取数据 从订单表中获取数据,我使用

  • $ order = $ this-> model_reports-> getdatewiseOrder($ cid,$ startdate, $ enddate);

我正在使用

从order_item获取数据
  • $ item [$ x] = $ this-> model_reports-> getorderItem($ value ['id']);

    inside foreach loop         
    

我要以这种格式输出
                                                                                          enter image description here

0 个答案:

没有答案