使用PHP Laravel从MySQL中的多个表中搜索数据

I'm currently trying to implement a search data from multiple table in my mysql database.

Education table data is CSE, HSC, Diploma and JobCircular table data is BSc in CSE.

now i try to searching match CSE

my code is

$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]);

when job circular education requirements BSc in CSE I expect the result is education table data CSE

1个回答

$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(); 
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐