2017-10-01 62 views
0
$array = array('classesID' => 6); 
$this->db->select()->from($this->_table_name)->where($array)->order_by($this->_order_by); 
$query = $this->db->get(); 
return $query->result(); 

我需要获取classesID为6的行。某些行包含6,5,4。 所以我需要使用FIND_IN_SET查询以检索其中classesID是6如何在codeigniter查询中使用FIND_IN_SET?

请指引我

感谢

+0

你是说'classesID'列中的值可能是“4,5,6”? – DFriend

回答

0

你可以写这样的查询。

return $this->db->where('classesID' , '6')->order_by('column_name','desc')->get('table_name')->result_array(); 

如果需要任何帮助评论

+0

谢谢兄弟。我使用这个查询$ this-> db-> select() - > from(student) - > where('FIND_IN_SET(6,classesID)'); –

+0

但我不知道如何将ID从控制器传递给模型? –

0

试试这个

$array = array('classesID' => '5,6,7'); 
$this->db->select(); 
$this->db->from($this->_table_name); 
$this->db->where("FIND_IN_SET('classesID',".$array['classesID'].")",null,false); 
$this->db->order_by($this->_order_by); 
$query = $this->db->get(); 
return $query->result(); 
1

'Action history table with studentsIds as comma separated values

我需要得到具有学号 '4488' 和消息ID '1418'

$id = 1418; 
$student_id = 4488; 
    this->db->select('id, action_status, updated_on, student_ids'); 
    $this->db->where('message_id', $id); 
    $this->db->where('find_in_set("'.$student_id.'", student_ids) <> 0'); 
    $this->db->from('actions_history'); 
    $query = $this->db->get(); 

它会返回一个查询,如

SELECT id, action_status, updated_on, student_ids FROM actions_history WHERE message_id = '1418' AND find_in_set("4488", student_ids) <>0 
+0

这对我有用 – wahmal

+0

很高兴听到它在工作 –