Advertisement
Skorpius

MySQL Joins with ORDER BY

May 25th, 2022 (edited)
130
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $recipe = "SELECT * FROM recipes
  2.        JOIN recipe_ingredients ON recipes.recipe_id = recipe_ingredients.recipe_id
  3.        JOIN measurement_qty ON recipe_ingredients.measurement_quantity_id = measurement_qty.measurement_qty_id
  4.        JOIN measurement_units ON recipe_ingredients.measurement_id = measurement_units.measurement_id
  5.        JOIN ingredients ON recipe_ingredients.ingredient_id = ingredients.ingredient_id
  6.        ORDER BY section
  7.        ";
  8.  
  9. $stmt = $pdo->query($recipe);
  10.  
  11. $rows = $stmt->fetchAll(PDO::FETCH_GROUP);
  12.  
  13. foreach($rows as $recipe_id=>$recipe)
  14.             {
  15.                 $heading = $recipe[0];
  16.  
  17.                 foreach($recipe as $row)
  18.                 {
  19.                    
  20.                 }
  21. }
Advertisement
RAW Paste Data Copied
Advertisement