Here's how I would set this up:
Code:
bag id # | [candy type?] | colors
1 skittles red,red,blue,red,green....
34 M&Ms blue, blue, red, aqua
In your programming language, define a list (or even in the database if you need to):
$blues = array('blue','aqua','light blue','navy',.........);
Then query against the database for each of those colors; if any are present then a "blue" is there.
Everything else can be done in the same way.
If you want to set things up in a different way it's probably fine too, but you will need some sort of bag identifier (#, student's name, etc) and a list of colors in the bag. You could instead approach it in two other ways, but they seem more complex:
1. Have a column in each row for each color:
id#|blue|red|green
1--|20--|8--|6
2. Have a "candies" table instead of "bags" table and list every single candy individually, by bag id (that it is in) and by color.
Of course that seems messy, but if you want to do complex things like maybe later switch M&Ms from one bag to the other it would be possibly helpful.
I'd suggest just keeping it simple: bags with a list of colors in them.
Parse as needed... string functions can get complex, but probably easiest way overall.
The most efficient way may be to use idea (1) above if you are using a constant number/names of colors.
Bookmarks