[英]Searching comma related value with FIND_IN_SET with multiple search string Codeigniter
I am using FIND_IN_SET to get similar comma related values from database the problem what i am facing is if in string i am passing single value it is searching accurately but if i am sending multiple value in string it is not able to search 我正在使用FIND_IN_SET从数据库中获取类似的逗号相关值,我所面临的问题是,如果在字符串中我传递单个值,它正在准确地搜索,但是如果我在字符串中发送多个值,则它无法搜索
$search = "FIND_IN_SET('".$toteach."', level_whometoteach)";
$this->db->where($search);
$query=$this->db->get();
return $result = $query->result();
If here $toteach=5 and in level_whometotech 5 is present it search and give result but if, 如果这里$ toteach = 5,并且在level_whometotech 5中存在,它会搜索并给出结果,但是,
$teach=5,6 and level_whometoteach contains 5,6 no value is returned
Can i know the right way to do this 我能知道正确的方法吗
Well, FIND_IN_SET
will check for individual values separated by comma. 好吧, FIND_IN_SET
将检查以逗号分隔的各个值。 In your case, you should use IN
clause. 对于您的情况,应该使用IN
子句。
Try this query. 试试这个查询。
$search = "level_whometoteach IN (".$toteach.")";
$this->db->where($search);
$query=$this->db->get();
return $result = $query->result();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.