我想在我的网站中包含搜索功能。
我想允许根据用户名、城市、学院/学校名称、员工进行搜索。name 是必填项,其他是可选字段。我有以下表格
users(id,fname,lname,city)
profile_pic(id,pic,userid)//userid from users(id)
educationdetail(eduid,school,userid)//userid from users(id)
employment(empid.employeer,userid)//userid from users(id)
在 profile_pic 中,每个用户只有一张图片;在educationdetail用户可以添加多个学校大学详细信息在就业用户可以添加多个工作详细信息
出于搜索目的,我使用以下查询:
SELECT distinct s.id, s.fname, s.lname,pr.pic
FROM users as s LEFT JOIN profile_pic as pr
on s.id = pr.userid
LEFT JOIN educationdetail as edu
on s.id=edu.userid
LEFT JOIN employment as emp
on s.id=emp.userid
where s.fname like '%m%' and s.lname like '%%%' and s.city like '%%%'
这是给出适当的细节
但是当包含几个参数时,它没有显示任何结果
SELECT distinct s.id, s.fname, s.lname,pr.pic
FROM users as s LEFT JOIN profile_pic as pr
on s.id = pr.userid
LEFT JOIN educationdetail as edu
on s.id=edu.userid
LEFT JOIN employment as emp
on s.id=emp.userid
where s.fname like '%m%' and s.lname like '%%%' and s.city like '%%%'
and edu.school='%%%' and emp.employeer='%%%';
显示
Empty set (0.00 sec)