Du bør normalisere dette.
3 tabeller:
Image {image_id, name}
Colors {color_id, red, green, blue, alpha}
ImageHasColor {image_id, color_id, number_of_times_appeared}
Det skal være nemt at indsætte data, brug ...insert_id
funktioner til at hente id'et fra den række, du lige har indsat.
Vælg med joins som:
SELECT * FROM
Image i
JOIN ImageHasColors h
ON i.image_id = h.image_id
JOIN Colors c
ON c.color_id = h.color_id
ORDER BY i.image_id
Tjek dette link om, hvordan du konverterer HEX-farve til RGB-værdier:http://bavotasan.com/2011/convert-hex-color-to-rgb-using-php/
Søg top 10 virkelig røde billeder:
SELECT * FROM
Image i
JOIN ImageHasColors h
ON i.image_id = h.image_id
JOIN Colors c
ON c.color_id = h.color_id
WHERE c.red > 200
AND c.green < 50
AND c. green < 50
ORDER BY h.number_of_times_appeared
LIMIT 10
Søg temmelig sorte billeder:
SELECT * FROM
Image i
JOIN ImageHasColors h
ON i.image_id = h.image_id
JOIN Colors c
ON c.color_id = h.color_id
WHERE c.red < 30
AND c.green < 30
AND c. green < 30
ORDER BY h.number_of_times_appeared
LIMIT 10