问题
$skills = explode(',', 'good listener,topper,leader');
$teacherID = 7;
function search_follower($teacherID, $skills, $limit, $start) {
$this->db->limit($limit, $start);
$this->db->select('student_skills.user_id');
$this->db->from('student_skills');
$this->db->join('followers', 'followers.student_id = student_skills.user_id', 'FULL JOIN');
foreach ($skills as $skill) {
$this->db->like('student_skills.name', $skill);
$this->db->or_like('student_skills.name', $skill);
}
$this->db->where('followers.teacher_id', $teacherID);
$query = $this->db->get();
if ($query->num_rows() > 0) {
foreach ($query->result() as $row) {
$data[] = $row;
}
return $data;
}
return false;
}
student_skills table:
id name user_id
1 topper 5
2 leader 5
3 good listener 6
4 toper 6
follower table:
id teacher_id student_id
1 7 5
1 7 6
1 7 8
I have written the above model function to fetch student id's of student who follow particular teacher ($teacherID) and have specified skills ($skills) from student_skills table..
when i run the above function with multiple skills (ex: good listener, topper etc) or single skills (ex: topper) it runs without showing any error..but it gives me all the students who have the specified skills and i would like to have only the students who follow the particular teacher..and have the specified skills..
but when i comment the or_like statement it gives me required result but multiple skills not working.. ex: topper working and ex:topper,topper working but ex: topper,leader not working
I am struggling from 2 days to solve this.. but not yet came to any solutions....
any suggest or help would be a great help.. thanks in advance.
回答1:
Try modifying select sentence.
$this->db->select('student_skills.*, followers.*');
来源:https://stackoverflow.com/questions/21416415/join-not-giving-required-result-when-using-or-like-codeigniter