Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7768231
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T15:52:04+00:00 2026-06-01T15:52:04+00:00

I have a table with images and tags in it (called tbl_images ) image_file

  • 0

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 as Atag98, 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 do LIKE '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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T15:52:05+00:00Added an answer on June 1, 2026 at 3:52 pm

    A better solution to store tags with images would be to create a separate table where tags are linked to images. You would then create a row for each tag, e.g.

    image_file (FK)  tag
    ---------------  -----------
    test.png         tag1
    test.png         another_tag
    test.png         tag2
    hi.jpg           tag9
    hi.jpg           tag1
    hi.jpg           another_tag
    hi.jpg           qwerty
    

    You can then simply look up which tags are related to an image:

    SELECT tag FROM tags WHERE image_file = 'test.png'
    

    or which images are related to a certain tag:

    SELECT image_file FROM tags WHERE tag = 'tag1'
    

    All problems with LIKE which you described in your question are avoided using this approach. Full-text search is not needed when normalizing your database like this.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an images table and tags table. I also want to have a
I have three tables, images, tags and links(the table below) ImageNO | TagNO 1
I have a table in SQL Server 2005. alt text http://www.techpint.com/sites/default/files/images/table.JPG I want to
Basically I have a database with two tables, that is, Updates table and Images
I have a list of images in a table like so: <div id=scroll-uploader-photos> <table>
I have 2 ways of adding images to a table and, which is most
I have two tables, content and images (and a ContentImages table for the one
my mail have some tempalte with HTML tags includes and images.. when i am
I have a view that displays multiple images and those images' associated tags. I
Okay, so i have three tables, images(ID, name,..) , tags(ID, name, ..) and one

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.