Hossam Aldeen Ahmed Hossam Aldeen Ahmed - 7 months ago 54
MySQL Question

Yii2 add like where with one side %

i want to add where condition in yii2 with

condition with one side

to be like

where name like 'value%'

Table::find()->filterWhere(['like', 'name' , $_GET['q'].'%' ])

that result query like

where name like '%value\%%'


You need set the third operand to false in order to use custom where like conditions:

Table::find()->where(['like', 'name', $_GET['q'] . '%', false]);

From the Docs:

Sometimes, you may want to add the percentage characters to the matching value by yourself, you may supply a third operand false to do so. For example, ['like', 'name', '%tester', false] will generate name LIKE '%tester'.