I am fetching code from codeignitor using implode function. here is the code
$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();
The problem is i can not able to fetch data for
echo '<pre />';
print_r($query1); exit;
return $query1->result();
When i try enter this database query manually in mysql workbench it is working, but by code it displays null value. is that anything missing in code? please guide me. below is my output.
Output
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] =>
)
You should use the FIND_IN_SET
clause in your query:
$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();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.