0

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

Sumit Nair
  • 327
  • 1
  • 4
  • 20

1 Answers1

1

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();
A J
  • 3,970
  • 14
  • 38
  • 53
  • waaaao its working super just as i wanted thanks alot buddy @AJ – Sumit Nair May 07 '16 at 06:53
  • hi i am facing a problem when entering non comma related value like sometime in string i get comma related value and some time non comma related value so what should i do in this case , now for comma related value it is showing correct output but for non coma related it is not showing any output what should i do ? @A J – Sumit Nair May 09 '16 at 07:12
  • for non-comma separated you can try equality operator. – A J May 09 '16 at 17:24
  • how should i check when cooma related value is coming and when normal value ? – Sumit Nair May 10 '16 at 08:28