douyingmou1389 2013-02-08 11:34
浏览 82
已采纳

使用codeigniter中的活动记录从mysql复杂的数据集

i am generating a invoice generation application. In that, i have a table that stores individual items of invoice with flags buyer and invoice_no. These flags help me get a aggregate invoice construct from rows. This is the function:

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);
    }


}

The problem is that i am not getting item details What may be the mistake?

  • 写回答

1条回答 默认 最新

  • dt3358 2013-02-08 13:27
    关注
    $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++;
    
    }
    

    This should give you the desired result.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 用matlab 设计一个不动点迭代法求解非线性方程组的代码
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler
  • ¥15 oracle集群安装出bug
  • ¥15 关于#python#的问题:自动化测试