Dovresti normalizzarlo.
3 Tabelle:
Image {image_id, name}
Colors {color_id, red, green, blue, alpha}
ImageHasColor {image_id, color_id, number_of_times_appeared}
L'inserimento dei dati dovrebbe essere semplice, usa ...insert_id
funzioni per ottenere l'id dalla riga appena inserita.
Seleziona con join come:
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
Controlla questo link su come convertire il colore HEX in valori RGB:http://bavotasan.com/2011/convert-hex-color-to-rgb-using-php/
Cerca le prime 10 foto davvero rosse:
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
Cerca immagini piuttosto nere:
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