0

我正在尝试使用 select2 过滤 yii2 gridview

在 ModelSearch 我有

 ->andFilterWhere(['like', 't_persons.functions', $this->functions ])

不幸的是,字符串 (1) 也匹配 10 和 11

在此处输入图像描述

如何过滤逗号分隔字段中的整数值?

4

2 回答 2

0

To match a single value in a comma-separated field use FIND_IN_SET, e.g.:

SELECT * FROM t_persons WHERE FIND_IN_SET('3', functions);

To integrate that into Yii2, you might (if I've understood your nomenclature correctly) use:

->andFilterWhere(new Expression('FIND_IN_SET(:function_to_find, functions)'))->addParams([':function_to_find' => $this->functions])->asArray()->all();
于 2020-11-20T14:34:39.343 回答
0

如果您有一串逗号分隔值,我会尝试:

->andFilterWhere('t_persons.functions in ('.$this->functions.')')
于 2017-04-13T15:30:17.543 回答