Sumit Nair Sumit Nair - 1 year ago 302
SQL Question

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)";
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

Answer Source

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.")";
    return $result = $query->result();
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download