L
L
Li2016-03-30 20:41:07
PHP
Li, 2016-03-30 20:41:07

How to find array value in database?

Good afternoon.
The database has a table `events` (Events) in which there is a field `categories` ( Categories of events )
in the categories field there is an array with category identifiers of this format ["1", "2", "3", etc.].
The question is how you can display the event knowing the category id.
I tried to solve the problem in this way:

$result = $db->query('SELECT * FROM events WHERE categories LIKE "%'.$category_id.'%" ');

However, this method does not work properly.
Thank you in advance for your help.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
T
ThunderCat, 2016-03-30
@cubaPro

implemented through the pop, well, if not refactor, then
and it's sad

D
DuD, 2016-03-30
@DuD

You need to use where categories in ('.implode(",", $category_id).')

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question