Question

Using codeigniter active records method, i want to find out which rows contains the id=6.
Pls advise.

$this->db->like('id', 6);  
$this->db->get('mytable');  

   | id       |
---+----------+---
   | 3,16,8,6 |
---+----------+---
   | 6,66     |
---+----------+---
   | 7,560    |
---+----------+---
Was it helpful?

Solution

you could use FIND_IN_SET, like:

$searchterm = 6;
$where = "FIND_IN_SET('".$searchterm."', id)";  
$this->db->where( $where );
$this->db->get('mytable');  
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top