codeigniter活动记录选择查询不起作用

时间:2014-02-01 15:38:56

标签: php mysql codeigniter select activerecord

我想从industry获得candidate database,因为我写了以下内容:

 $candidateID = '1,2,3,4,5,6,7,8,9';

 function get_industry($candidateID) {
    $this->db->select('current_industry');
    $this->db->group_by('current_industry');
    $this->db->from('candidate_details');

    $this->db->where_in('user_id', $candidateID);

    $query = $this->db->get();
    print_r($this->db->last_query());
    if ($query->num_rows() > 0) {
        foreach ($query->result() as $row) {
            $data[] = $row;
        }
        return $data;
    }
    return false;
}

但是当我执行此查询时,它只返回first 9候选人的行业{/ 1}}

我不知道我在这里失踪了什么..任何帮助或建议都会有很大的帮助..提前谢谢..

3 个答案:

答案 0 :(得分:2)

您需要将数据作为数组传递到where_in

$this->db->where_in('user_id', array(1,2,3,4,5,6,7,8,9));

在你的情况下尝试

$this->db->where_in('user_id', explode(",",$candidateID));

答案 1 :(得分:1)

而不是$this->db->where_in('user_id', $candidateID);

你可以这样做:

 $this->db->where_in('user_id', explode(",",$candidateID));

答案 2 :(得分:0)

试试这个

 $candidateID = '1,2,3,4,5,6,7,8,9';

function get_industry($candidateID) {
  $where = 'user_id in ('.rtrim($candidateID, ",").')';
  $this->db->select('current_industry');
  $this->db->group_by('current_industry');
  $this->db->from('candidate_details');

  $this->db->where($where);

$query = $this->db->get();
print_r($this->db->last_query());
if ($query->num_rows() > 0) {
    foreach ($query->result() as $row) {
        $data[] = $row;
    }
    return $data;
}
return false;
}