I am trying to create a code to do the following:
For each item, display the ingredients under it
Here is my code:
$result = mysqli_query($con,
"SELECT *
FROM recipe_ingredients ri
JOIN recipes r
ON ri.recipe_id = r.recipe_id
JOIN measurement_units mu
ON ri.measurement_id = mu.measurement_id
JOIN measurementqty mq
ON ri.measurement_qty_id = mq.measurementqty_id
JOIN ingredients i
ON ri.ingredient_id = i.ingredient_id;
");
echo "<table align='center' border='1' style='width: 600px'>";
echo "<tr>";
echo "<th>Recipe Name</th>";
echo "<th>Ingredients</th>";
echo "</tr>";
while ($row = mysqli_fetch_array($result)) {
echo "<tr>";
echo "<td><center>" . $row['recipe_name'] . "</center></td>";
echo "<td><center>" . $row['qty_amount'] . " " . $row['measurement_description'] . " " . $row['ingredient_name'] ." </center></td>";
echo "</tr>";
}
echo "</table>";
It is currently outputting a table that looks like this:
Recipe Name | Ingredients |
---|---|
Vanilla Cupcakes | 200 grams sugar |
Vanilla Cupcakes | 300 grams flour |
Vanilla Cupcakes | 1 tbsp vanilla |
Here is what I want my results to look like instead
Vanilla Cupcakes |
---|
200 grams sugar |
300 grams flour |
300 grams flour |
1 tbsp vanilla |
50 grams butter |
I am still playing around with foreach loops but cannot get any to work.