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

  • SEARCH
  • Home
  • 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 3699128
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T05:03:56+00:00 2026-05-19T05:03:56+00:00

For this question, I’m looking to see if anyone has a better idea of

  • 0

For this question, I’m looking to see if anyone has a better idea of how to implement what I’m currently planning on implementing (below):

I’m keeping track of a set of images, using a database. Each image is represented by one row.

I want to be able to search for images, using a number of different search parameters. One of these parameters involves a search-by-color option. (The rest of the search stuff is currently working fine.)

Images in this database can contain up to seven colors:

-Red

-Orange

-Yellow

-Green

-Blue

-Indigo

-Violet

Here are some example user queries:

“I want an image that contains red.”

“I want an image that contains red and blue.”

“I want an image that contains yellow and violet.”

“I want an image that contains red, orange, yellow, green, blue, indigo and violet.”

And so on. Users make this selection through the use of checkboxes in an html form. They can check zero checkboxes, all seven, and anything in between.

I’m curious to hear what people think would be the most efficient way to perform this database search.

I have two possible options right now, but I feel like there must be something better that I’m not thinking of.

(Option 1)
-For each row, simply have seven additional fields in the database, one for each color. Each field holds a 1 or 0 (true/false) value, and I SELECT based on whatever the user has checked off. (I didn’t like this solution so much, because it seemed kind of wasteful to add seven additional fields…especially since most pictures in this table will only have 3-4 colors max, though some could have up to 7. So that means I’m storing a lot of zeros.) Also, if I added more searchable colors later on (which I don’t think I will, but it’s always possible), I’d have to add more fields.

(Option 2)
-For each image row, I could have a “colors” text field that stores space-separated color names (or numbers for the sake of compactness). Then I could do a fulltext match against search through the fields, selecting rows that contain “red yellow green” (or “1 3 4”). But I kind of didn’t want to do fulltext searching because I already allow a keyword search, and I didn’t really want to do two fulltext searches per image search. Plus, if the database gets big, fulltext stuff might slow down.

Any better options that I didn’t think of?

Thanks!

Side Note: I’m using PHP to work with a MySQL database.

  • 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-05-19T05:03:57+00:00Added an answer on May 19, 2026 at 5:03 am

    You can create a second table called colors.

      colors = (color_id, name)
    

    and a relationship table called image_colors.

      image_colors = (image_id, color_id)
    

    Then in the image_colors table you add a row for each color of each image.

     image_colors
     Image_id     Color_id
      1            1
      2            3
      2            4
    

    So image 1 has a single color but image 2 has two colors.

    To find an image with say color 4 and 5 you can then

        select  i.fileName, etc
        from images i JOIN image_colors c ON
             i.image_id = c.image_id
        where
             c.color_id = 4 OR
             c.color_id = 5
    

    The advantage of this solution is the ease of querying.

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

Sidebar

Related Questions

This question is similar in concept to this one , except I see I
This question came up from what I see on a clients side: Intermittent Connection
This question has been asked a lot of times in many forums. But I
This question has been asked before, but I would like a little more detail
This question is about tidying up code and better management of said code butI'm
This question has been asked many times before, but they all seem to relate
This question has been asked before but the accepted solution (given by the question
This could be a duplicate question, but I have no idea what search terms
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
This question has been thrown around without an answer. YES, we can hide the

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.