Answer the question
In order to leave comments, you need to log in
How to implement mysql query with variable and string comparison?
There is a table: media_tags(`media_tag`, `media_ids`) in which media_ids is a string like 1,2,3,10 etc.
There is an incoming variable $
media_id which contains the value of $media_id ?
For example:
media_tag 1 | media_ids 1,2,3,5
media_tag 2 | media_ids 4,6,8,10
media_tag 3 | media_ids 2,9,10,11
How to pull out tag_2 and tag_3 if, say, media_id = 10
---
I, of course, assume that it is possible through entering all ids into an array and comparing with the array .. but how correct and productive is it if media_tag_s can be both 100 and 10'000 (over many).. ?
It's also necessary to create a cycle of so many arrays and compare them. Maybe there is a more optimized way, or a function?
Answer the question
In order to leave comments, you need to log in
Option 1 (shitcode):
Option 2 (correct):
Store media_id in an int field (in a separate table) or int[] (in the same table, but only for PostgreSQL)
How can I write a query to pull out all `media_tag`_s whose `media_ids` string contains the value of $media_id ?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question