dtrpv60860 2014-01-28 20:42
浏览 42

使用or_like codeigniter时,join不会提供所需的结果

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

  • duandingyou3331 2014-01-28 23:21
    关注

    Try modifying select sentence.

    $this->db->select('student_skills.*, followers.*');
    
    评论

报告相同问题?

悬赏问题

  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?