php - 使用 PHP Laravel 从 MySQL 中的多个表中搜索数据
问题描述
我目前正在尝试从我的 mysql 数据库中的多个表中实现搜索数据。
Education 表数据为CSE
, HSC
,Diploma
JobCircular 表数据为BSc in CSE
。
现在我尝试搜索匹配CSE
我的代码是
$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]);
当我期望的工作循环教育要求BSc
是CSE
教育表数据时CSE
解决方案
$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();
推荐阅读
- java - 自动发送whatsapp消息
- assembly - MIPS Counting Number of 1's given a user input(B 指令不在 MARS 中跳转)
- python - 如何获取 MongoDB 存储的视频文件的剪辑?
- sql - 在 oracle 中编辑请求(添加正确的左侧连接)
- javascript - 在 Vue.js 中调用 AJAX 后重新加载轮播
- excel - 过滤后vba计数可见行
- asp.net-mvc - 返回 RedirectToAction 不起作用
- vue.js - 奇怪的 VueJS 路由行为
- magento - Magento 1.9 - OroCRM 更新同步无法正常工作
- r - 非整数计数的泊松 GLM - R