[英]I have a column which has comma separated value how to search these value with an array
here is table 这是桌子
+----+----------------------+
| id | title |
+----+----------------------+
| 1 | math,science,english |
| 2 | social,hindi |
+----+----------------------+
how to search column if one of the value match in the given array in my sql active record 如何搜索列中值之一是否与我的sql活动记录中给定数组匹配
$array=array('math','computer','english');
the result should be 结果应该是
+----+----------------------+
| id | title |
+----+----------------------+
| 1 | math,science,english |
+----+----------------------+
使用mysql find_in_set
方法, 单击此处查看文档。
You can use FIND_IN_SET() to solve this. 您可以使用FIND_IN_SET()解决此问题。
if($array)
{
$this->db->group_start();
$this->db->where("FIND_IN_SET('$array[0]', title) != ",0);
for($x=1; $x < count($array); $x++)
{
$this->db->or_where("FIND_IN_SET('$array[$x]', title) != ",0);
}
$this->db->group_end();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.