I have a table with images and tags in it (called tbl_images
)
image_file image_tags
---------- ----------------------------
test.png tag1 another_tag tag2
hi.jpg tag9 tag1 another_tag qwerty
How would I do it so that:
- searching 'another' returns nothing
- searching 'tag1' returns the test.png row
- searching 'tag1 another_tag' returns the test.png row
- searching 'qwerty tag2' returns nothing
?
As in, the ability to search using the full tag name and to search multiple tags at the same time if they all occur in the same image_tags field in the same row. Note:-
- I'm only searching within one field
- Its being done with a PHP search input (retrieved in
$_GET['search_terms']
) - I can't do
LIKE '%tag9%
because tag9 could appear in a larger tag, such asAtag98
, and as I said I would only like the exact tag match. - I can't do
LIKE ' tag9 '
(note the space before and after,) because tag9 may appear at the beginning of the image_tags field (where there is no space, so there would be no match) - I can't do
LIKE 'tag9 another_tag'
because I don't know if another_tag comes after tag9, similarly I can't doLIKE 'tag9%another_tag'
for the same reason; also tag9 could be part of a larger tag (as mentioned previously.)
Also, is fulltext search appropriate for this? And if so, could you provide an example please?
A tricky problem (for me anyway;) any help would be greatly appreciated.