douchun3680
2018-05-16 00:53
浏览 729
已采纳

通过将查询结果放入foreach中的另一个查询,从Laravel获取结果

I want to get results from Laravel by putting the results from the query into another query in foreach.

$first = DB::connection('store')
->table('entire_store')
->select('name', 'code', 'category', 'direct')
->where('open', 'Y')
->get();

The first query takes the information of the points and processes them into an array.

Match the information of the branches with the workplace in the employee table.

I want to save the workplace information of the employees together.

$temp = array();    
$i =0;    
foreach($first as $key => $item){

    $temp[$i]['name'] = $item->name;
    $temp[$i]['code'] = $item->code;

    $temp[$i]['category'] = $item->category;
    $temp[$i]['direct'] = $item→direct;

    $second = DB::connection('store')
     ->table('entire_employer')
     ->SELECT('mgr_no','mgr_id', 'status')
     ->where('store',$item->code)->get();
    //I tried.
    foreach($second as $key2 => $item2){
        $temp[$i]['mgr_id'] = $item2->mgr_id;
    }
    $i++;

}

I want to store the values from this query in temp_array.

I get an error if I try to save the value of the second query and print the value of temp_array ().

Is there anything more I need to do to check temp_array ()?

图片转代码服务由CSDN问答提供 功能建议

我想通过将查询结果放入foreach中的另一个查询中来获取Laravel的结果。

  $ first = DB :: connection('store')
-> table('whole_store')
-> select('name','code','category  ',''direct')
-> where('open','Y')
-> get(); 
   
 
 

第一个查询 获取点的信息并将它们处理成一个数组。

在employee表中将分支的信息与工作区匹配。

I 想要将员工的工作场所信息保存在一起。

  $ temp = array();  
 $ i = 0;  
foreach($ first as $ key => $ item){
 
 $ temp [$ i] ['name'] = $ item-> name; 
 $ temp [$ i] ['code'  ] = $ item->代码; 
 
 $ temp [$ i] ['category'] = $ item-> category; 
 $ temp [$ i] ['direct'] = $ item→direct  ; 
 
 $ second = DB :: connection('store')
  - > table('entire_employer')
  - > SELECT('​​mgr_no','mgr_id','status')
  -  > where('store',$ item-> code) - > get(); 
 //我试过。
 foreach($ second as $ key2 => $ item2){
 $ temp [  $ i] ['mgr_id'] = $ item2-> mgr_id; 
} 
 $ i ++; 
 
} 
   
 
 

我想存储 temp_array中此查询的值。

如果我尝试保存第二个查询的值并打印temp_array()的值,则会出错。 \ n

我还需要做些什么才能检查temp_array()吗?

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

1条回答 默认 最新

相关推荐 更多相似问题