codeigniter active record select query not working

i would like to get industry of a candidate from the database for that i have written the following:

 $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;
}

but when i execute this query it only returns me the industry of the first candidate out of 9

i dont know what i am missing here..any help or suggestion would be a great help..thanks in advance..

Answers


Try this one

 $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;
}

You need to pass the data as array in the where_in

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

In your case try like

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

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

You can do like this:

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

Need Your Help

Inspect marshalled Pojo with a Processor with Camel and Bindy

java apache-camel pojo bindy

I have a flat file, in which each line needs to be captured and unmarshalled into a POJO. I am using Camel and Bindy and utilizing the Splitter EIP. For some reason i am not able to inspect the POJO (

google charts using .net wrapper produces 'Table has no columns' error

javascript asp.net json google-visualization google-datatable

I an using the Google.DataTable.Net.Wrapper to pass JSON data to Google charts and try to create a line chart. The call to my web service is passing back JSON, which looks completely valid to me,, ...