I wnat to test a field with multiple values against single value, my SQL is like .
我想针对单个值测试具有多个值的字段,我的SQL是这样的。
WHERE id (1);
Database values are like
数据库值就像
id
---
1,2
2,3
1,3,4
codeigniter
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.
但它不工作。请帮我解决这个问题。
3 个解决方案
#1
2
What if you use like()
instead of where()
如果您使用like()而不是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注意:如果2是2,则22,222将通过这个
#2
3
To find the values from a given set you can use FIND_IN_SET
要从给定的集合中查找值,可以使用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
注意:这种类型的设计被认为是糟糕的设计,您应该规范化您的结构,我建议您查看一下数据库规范化
#3
0
Please try this one:
请试试这个:
$this->db->select('*')->from('table_name')
->where("column_name LIKE '%$key_values%'")->get();
#1
2
What if you use like()
instead of where()
如果您使用like()而不是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注意:如果2是2,则22,222将通过这个
#2
3
To find the values from a given set you can use FIND_IN_SET
要从给定的集合中查找值,可以使用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
注意:这种类型的设计被认为是糟糕的设计,您应该规范化您的结构,我建议您查看一下数据库规范化
#3
0
Please try this one:
请试试这个:
$this->db->select('*')->from('table_name')
->where("column_name LIKE '%$key_values%'")->get();