I have a MySQL Database with hundreds of items identified by 2 different values: model
and color
.
Ex:
model | color
------|------
001 | 1
001 | 1
001 | 2
004 | 1
004 | 2
I'm printing a table of all different avaliable items with a php script where identical items should be skipped. The output should be something like this:
model | color
------|------
001 | 1
001 | 2
004 | 1
004 | 2
Notice that the item model: 001, color:1
should only be displayed once.
What is the best way to get the job done ? I was considering adding a string of model:color
to a array $listed
after each item is added and then check with in_array()
if the item was already listed. Is this a acceptable approach or is there a less dummy solution ?
PS: There are other values to be retrieved from the database to display on the table, such as 'name', 'value', 'size'. I'm not sure how that will make a difference.
If you'll make sugestions please leave some code as example.
Many thanks!