Answer the question
In order to leave comments, you need to log in
How to implement partial search by string?
Hello. There was suddenly a need to make in one of the projects a page for displaying articles by certain tags. Tags are passed in the search string using the GET parameter and look like this:
site/topics?tags=0,3,5
Topic::where('tags', 'LIKE', '%' . $tags . '%')->get(...)...;
0,5
, and the database contains a string for the article 0,3,5
(that is, there is still a value between 0 and 5), then this article does not fall into the final selection. That is, the search goes on the full line. How to implement a partial search on a string so that MySQL takes into account all the tags included in it, regardless of their order?
Answer the question
In order to leave comments, you need to log in
1. Or change a column in the database to json
and the minimum then will be mysql 5.5 PHP side, after that - select content for output based on the selected article IDs.
Your tags are stored incorrectly. It is necessary to create a 3rd table to store the correspondence of the article and tags. And store tags in a separate table. Then flexibility increases and such a problem does not arise.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question