简体   繁体   中英

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

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

$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. In your case, you should use IN clause.

Try this query.

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

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.

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