download201401 2019-04-07 11:39 采纳率: 0%
浏览 239

使用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条回答 默认 最新

  • dongmeng1402 2019-04-07 12:09
    关注
    $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(); 
    
    评论

报告相同问题?

悬赏问题

  • ¥15 安装svn网络有问题怎么办
  • ¥15 Python爬取指定微博话题下的内容,保存为txt
  • ¥15 vue2登录调用后端接口如何实现
  • ¥65 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥15 latex怎么处理论文引理引用参考文献