join not giving required result when using or_like

2019-09-19 03:51发布

$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条回答
三岁会撩人
2楼-- · 2019-09-19 04:18

Try modifying select sentence.

$this->db->select('student_skills.*, followers.*');
查看更多
登录 后发表回答