I am currently trying to put a cookbook together that holds a collection of recipes. This is purely to try to help me improve my knowledge of mysql/php.
I have found an outline for the database at Link to outline
The database structure is
I am using PHP/PDO
Currently my issue is, I have the output but within my while loop I have a title, sub title and paragraph and then the ingredients for said recipe however I because I have the title etc inside the while loop it then outputs for every ingredient so I have title, sub title, paragraph, ingredient then title and so on.
$recipe4 = "SELECT * FROM recipes
JOIN recipe_ingredients ON recipes.recipe_id = recipe_ingredients.recipe_id
JOIN measurement_qty ON recipe_ingredients.measurement_quantity_id = measurement_qty.measurement_qty_id
JOIN measurement_units ON recipe_ingredients.measurement_id = measurement_units.measurement_id
JOIN ingredients ON recipe_ingredients.ingredient_id = ingredients.ingredient_id
";
$stmt = $pdo->query($recipe4);
while($row = $stmt->fetch(PDO::FETCH_ASSOC)){
echo "<h1>".$row['recipe_name']."</h1>";
echo "<em>".$row['recipe_description']."</em>";
echo "<p>".$row['qty_amount']." ".$row['measurement_description']." ".$row['ingredient_name']."</p><br>";
}
Output
There should only be 1 title then all the ingredients listed underneath.
I realise the title etc should be outside the while loop however if I move the code outside the while loop then the title etc does not display.
I realise that this code might not be the most efficient which maybe part of the problem.
I would appreciate pointers/advice on how to improve on my current code.
Thanks