Maybe someone can point me in the right direction with this example:
(id, color, item)
(1, red, car)
(2, red, apple)
(3, red, barn)
(4, red, crayon)
(5, yellow, sun)
(6, yellow, butter)
(7, brown, bag)
(8, red, fingernail)
This is the result (wrong format, of course) of a
SELECT * from table
I'd like it to display the following:
RED
car
apple
barn
crayon
fingernail
YELLOW
sun
butter
BROWN
bag
I don't know how to just pull 1 instance of the color out, display it independent of the rest of the data, and then grab the details. There may be additional colors added, or there may be colors in the database without items of that color.
Can someone post a generic solution?
I am thinking first, grab all the items, and then put a single instance of each color into an array. Following this, do a while loop that grabs the records that have the appropriate color and display those.
The problem is, I am new to php and cannot grasp the methodology or the language to do this. I can see the logic, but don't know the syntax. For all I know, there is an even better solution.
If I had any hair left to pull out, I would.