首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >用PHP Laravel在MySQL中实现多表查询

问用PHP Laravel在MySQL中实现多表查询
EN

Stack Overflow用户
提问于 2019-04-07 19:39:23
回答 1查看 50关注 0票数 0

我目前正在尝试在我的mysql数据库中实现从多个表中搜索数据。

教育表数据为CSE、HSC、Diploma,JobCircular表数据为BSc in CSE。

现在我尝试搜索match CSE

我的代码是

代码语言:javascript
复制
$profileId = Auth::guard('company')->user()->id;
$user_id = Applyer::
           where('com_id','=',$profileId)
           ->where('circular_id','=',$id)
           ->pluck('user_id')[0];

$examination = Education::selectRaw('subject')->where('user_id','=',$user_id)->orderBy('id','desc')->get();

   foreach ($examination as $exam => $sub) {     
      $exam_list = JobCircular::where('education_requirements','LIKE', "% 
                  {$sub}%")->get();
      }

echo "<pre>";
print_r([$exam_list]);

当作业循环显示CSE中的教育要求数据时,我希望得到的结果是教育表BSc CSE

EN

回答 1

Stack Overflow用户

发布于 2019-04-07 20:09:02

代码语言:javascript
复制
$needed_exam_ids = [ ];

    $examination = 
    Education::where('user_id','=',$user_id)- 
    >orderBy('id','desc')->get();

   Foreach ($examination as $data) {     
        $exam_list = 
  JobCircular::where('education_requirements','LIKE', "% 
                  {$data->subject}%")->count();
       if($count > 0)
       {
           // get exam id if 'cse' exist
           array_push($needed_exam_ids,$data->id);
       }
      }

// the result you want.
$education_data = Education::whereIn('id',$needed_exam_ids)->get(); 
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55558612

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档