I wnat to test a field with multiple values against single value, my SQL is like .
WHERE id (1);
Database values are like
id --- 1,2 2,3 1,3,4
codeigniter
$this->db->select('*'); $this->db->from('content'); $this->db->where('name', $name); $this->db->where('id', $id);
I tried
$this->db->where_in('id', explode(',', $id));
but its not working.Please help me to solve this.
To find the values from a given set you can use FIND_IN_SET
$this->db->where("FIND_IN_SET(".$id.",id) >", 0);
Note: This type of design is considered as a bad design and you should normalize your structure, I suggest you to have a look at Database Normalization
What if you use like()
instead of where()
$this->db->like('id', $id);
// Produces: WHERE `id` LIKE '%2%' ESCAPE '!'
Note: If 2 is the value
2
,22
,222
will pass through this
Please try this one:
$this->db->select('*')->from('table_name')
->where("column_name LIKE '%$key_values%'")->get();
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.