0

我正在生成发票生成应用程序。在那,我有一个表,其中存储带有买方和invoice_no标志的发票的各个项目。这些标志帮助我从行中获取聚合发票构造。这是功能:

public function invoice_get()
{
    $data=array();


    $this->db->group_by('invoice_no');
    $this->db->order_by('invoice_no','asc');
    $Q=$this->db->get('sales');
    echo $Q->num_rows();
    if($Q->num_rows()>0)
    {
        foreach($Q->result_array() as $row)
        {

            if(!isset($data[$row['invoice_no']]))
            {
                $data[$row['invoice_no']]['date']=$row['date'];
                $this->db->where('id',$row['buyer']);
                $q=$this->db->get('ledgers');
                $data[$row['invoice_no']]['buyer']=$q->row();
            }
            else
            {
                $this->db->where('id',$row['item_id']);
                $i=$this->db->get('inventory');
                $data[$row['invoice_no']]['items'][$row['item_id']]=$i->row();

            }

        }
        print_r($data);
        //$this->response($data);
    }


}

问题是我没有得到项目详细信息可能是什么错误?

4

1 回答 1

0
$i = 1; 
foreach ($q->result_array() as $row){

$data[$row['invoice_number']]['date'] = $row['date'];
$data[$row['invoice_number']]['buyer']['id'] = $row['id'];
$data[$row['invoice_number']]['item'][$i]['name'] = $row['name'];
$data[$row['invoice_number']]['item'][$i]['description'] = $row['description']; 
//and more if you want to add....
$i++;

}

这应该会给你想要的结果。

于 2013-02-08T13:27:03.563 回答