You have two hypothetical tables:
TABLE 1
[id] [item] [amount] [cost]
1 hat 20 10
2 shoe 7 45
3 belt 2 25
TABLE 2 (many to many)
[item] [color]
hat blue
hat red
hat yellow
shoe black
shoe white
etc. etc.
and when you run a query, you want to output a list that includes all of both data like this:
[ITEM] [AMOUNT] [COST] [AVAILABLE COLORS]
hat 20 10 blue, red, yellow
shoe 7 45 black, white
etc.
If the colors weren't present, it'd be a single query to grab all that info from one table and process the array in a loop. But to accommodate TABLE 2
I can think of two ways to do it:
Brute Force: run a query for every single return to get the data from TABLE 2
, add commas, and insert it into the results array from TABLE 1
, then output HTML table
Ugly Workaround: add a new column to Table 1
and periodically update with strings of data from Table 2
behind the scenes
...there's a better way, right?