Multi-value field search (LIKE condition)

I have a multi-value field in my DB, which stores the values in the following format: |1|2|3|4|

Notice the enclosing ‘|’ (pipe symbols) at the beginning and end of the string. This makes it possible for me to search for an exact value in that field, for example ‘11’ will not match, but ‘1’ will.

I now wish to perform a foreach loop on this field.

foreach(Subcategory::model()->findAll('parent_cats LIKE :parent_cats',

array(':parent_cats'=>'%|'.$category->id.'|%')) as $subcategory)

But this does not seem to work - I get error "Invalid argument supplied for foreach()".

EDIT: Working now.

I would also like to know if this is supported.


I guess that there is something wrong with your syntax…

I you should add ‘params’ in your array