I think you're looking for a way to make a list of a single product and all it's variations. Or make a list of all products, and then for every product to show every variation of that product.
I'm assuming your tables look somewhat like this:
product
productId
description
variation
variationId
description
productVariation
productVariationId
productId
variationId
For a single product and all it's variations you could use the following query, that does two inner joins.
SELECT
P.description as product,
V.description as variation
FROM
product as P,
INNER JOIN
productVariation AS PV
ON PV.productId = P.productId
INNER JOIN
variation as V
ON V.variationId = PV.variationId
WHERE
P.productId = 1
For the whole list of products, just omit the WHERE clause.
If a product has no variations, it won't be included in the list. If you want that, use LEFT JOINs instead.
The query will return the following
product variation
shoe blue
shoe green
shoe red
hat green
hat purple
hat yellow
sock white
Update:
I'm guessing you want the data displayed as follows:
shoe
blue
green
red
hat
green
purple
yellow
sock
white
That can be done by the following PHP code.
$sql = "
SELECT
P.productId,
P.description as product,
V.description as variation
FROM
product as P,
INNER JOIN
productVariation AS PV
ON PV.productId = P.productId
INNER JOIN
variation as V
ON V.variationId = PV.variationId
";
$result = mysql_query($sql);
//first put all the results into an array so we can look backward and
//see previous items
$resultSet = array();
while($record = mysql_fetch_array($result)) {
$resultSet[] = $record;
}
for ( $i = 0 ; $i < count($resultSet) ; $i++ ) {
if ( $i == 0 ) {
//for the first item, show the product name
echo $resultSet[$i]['product'].'<br/>';
} else if ($resultSet[$i]['productId'] != $resultSet[$i-1]['productId']) {
//every time we encounter a new product
//display a new line and show the product name
echo '<br/>'.$resultSet[$i]['product'].'<br/>';
}
echo $resultSet[$i]['variation'].'<br/>';
}