Hi. I have a mysql field with a record like: [2,5,11].
I have a query like:

$query = $this->select()
    ->where('id = ?', $id);

This query work if record is of integer type: 5.
Is it possible to create a query to find 5 in the array? Please advise. Thanks.

Recommended Answers

All 5 Replies

Member Avatar

Best to dump it to a string and parse it using php functions.

Member Avatar


Maybe you could use the LIKE command.


Thank you all for reply.

I think it is not possible to use LIKE here because there may be found situation of [12,32] will return true when searching for 2.

I have tried FIND_IN_SET(). The problem is that it is working without '[]', but I need these square brackets.

Finally I've got the solution.

->where("FIND_IN_SET($id, TRIM(TRAILING ']' FROM (TRIM(LEADING '[' FROM `id`))))");
  1. First I get rid of the leading '['
  2. Then I get rid of the ']' from the end of the string
  3. After that I can use FIND_IN_SET to check if my id exists there.
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.