Let’s say we have 2 db tables.
First table “laptops”
id | name
1 apple
2 sony
…
and second table “colors”
id | color
1 white
2 black
2 red
2 blue
…
If I want to get some html table like
Laptop | Available colors
Apple 1 (white)
Sony 3 (red, blue, black)
…
I need to create “while” and query every time for every laptop. It will load server if there are more than 10 000 laptops for example. Is there any optimised way to get it work?
What you are looking for is a
SQL JOIN. However you need to have a table which links both tables together.Something like
e.g. if you want to Count colors you could do something like this: