I have a table that looks like this:
ID --> Product --> Color --> Size
1 --> Shirt --> Brown --> S
2 --> Shirt --> Brown --> L
3 --> Shirt --> Brown --> XXL
4 --> Shirt --> Black --> M
5 --> Shirt --> Black --> XS
6 --> Shirt --> Red --> XL
I'm trying to create an array that looks like this:
Array ( "Brown" => array("S", "L", "XXL"), "Black" => array("M", "XS"), "Red" => array("XL"))
The following gives me two separate arrays, one for colors, and one for sizes:
$query = "SELECT distinct(Color) FROM myTable WHERE Product='Shirt'";
$result = mysql_query($query);
while($row = mysql_fetch_assoc($result)) {
$Color .= $row['Color'].",";
}
$color_lookup = explode(",",substr($Color,0,-1));
foreach($color_lookup as $value) {
$query = "SELECT distinct(Size) FROM myTable WHERE Product='Shirt' AND Color='$value'";
$result = mysql_query($query);
while($row = mysql_fetch_assoc($result)) {
$Size .= $row['Size'].",";
}
$size_lookup = explode(",",substr($Size,0,-1));
}
But, I can't figure out how "match them up" the way I want. Also, I'm not sure if there's a better way to do the query, so if someone could help, I'd appreciate it.