来自MYSQL的价值为空

时间:2014-07-16 06:37:16

标签: php mysql codeigniter implode

我正在使用implode函数从codeignitor中获取代码。这是代码

$this->load->database();
        $session_data = $this->session->userdata('logged_in');
        $user_id = $session_data['user_id'];

        $this->db->select('skill_id');
        $this->db->from('user_info_skillset');
        $this->db->where('user_id',$user_id);
        $query = $this->db->get();
        foreach($query->result() as $row)
        {
            $skill_id[] = $row->skill_id;
        }

        $test = implode(',',$skill_id);

//        echo '<pre />';
//                print_r($test); exit;
        $this->db->select('project_id');
        $this->db->from('project');
        $this->db->where_in('required_skills',$test);
        $query1 = $this->db->get();

        echo '<pre />';
                print_r($query1); exit;
        return $query1->result();

问题是我无法获取

的数据
  echo '<pre />';
                print_r($query1); exit;
        return $query1->result();

当我尝试在mysql工作台中手动输入此数据库查询时,它正在工作,但是通过代码它显示空值。是代码中缺少什么?请指导我。下面是我的输出。

输出

CI_DB_mysql_result Object
(
    [conn_id] => Resource id #34
    [result_id] => Resource id #38
    [result_array] => Array
        (
        )

    [result_object] => Array
        (
        )

    [custom_result_object] => Array
        (
        )

    [current_row] => 0
    [num_rows] => 0
    [row_data] => 
)

1 个答案:

答案 0 :(得分:0)

您应该在查询中使用FIND_IN_SET子句:

$test = implode(',',$skill_id);
$where  = " FIND_IN_SET(required_skills,'".$test."') ";
$this->db->select('project_id');
$this->db->from('project');
$this->db->where( $where, false );
//$this->db->where_in('required_skills',$test);
$query1 = $this->db->get();