繁体   English   中英

使用FIND_IN_SET和多个搜索字符串Codeigniter搜索与逗号相关的值

[英]Searching comma related value with FIND_IN_SET with multiple search string Codeigniter

我正在使用FIND_IN_SET从数据库中获取类似的逗号相关值,我所面临的问题是,如果在字符串中我传递单个值,它正在准确地搜索,但是如果我在字符串中发送多个值,则它无法搜索

$search  = "FIND_IN_SET('".$toteach."', level_whometoteach)";
$this->db->where($search);
        $query=$this->db->get();
        return $result = $query->result();

如果这里$ toteach = 5,并且在level_whometotech 5中存在,它会搜索并给出结果,但是,

$teach=5,6 and level_whometoteach contains 5,6 no value is returned 

我能知道正确的方法吗

好吧, FIND_IN_SET将检查以逗号分隔的各个值。 对于您的情况,应该使用IN子句。

试试这个查询。

    $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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM