我搜索了 2 个好小时试图解决这个问题,但没有发现任何工作。我有 3 张桌子:
recipe recipe_ingredient recipe_steps
id id id
name recipe_id recipe_id
description ingredient_name step_description
sort_order ingred_order step_order
如果我只加入 recipe 和 recipe_steps 它工作正常
SELECT *
FROM recipe
JOIN recipe_steps ON recipe.id = recipe_steps.recipe_id
如果我尝试加入 recipe_ingredient,我会得到一个空数组
SELECT *
FROM recipe
JOIN recipe_steps ON recipe.id = recipe_steps.recipe_id
JOIN recipe_ingredient ON recipe.id = recipe_ingredient.recipe_id
这是我的代码的其余部分:
<?php
$query = "SELECT * FROM recipe JOIN recipe_steps ON recipe.id = recipe_steps.recipe_id JOIN recipe_ingredient ON recipe.id = recipe_ingredient.recipe_id";
$recipe = $mysqli->query($query);
if(!$result){echo mysql_error();}
?>
<?php while($result = $recipe->fetch_assoc()){
//var_dump($result);
$k = 0;
$nr = 1;
$desc = json_decode($result["step_description"],true); ?>
<li>
<h2> <?php echo $result["name"]; ?> </h2>
<p class="recipe_date">22/03/2013</p>
<p class="recipe_date">Categorii:</p>
<p><?php echo $result["description"]; ?></p>
<p>Timp preparare: <?php echo $result["hours"] . " h " . $result["minutes"] . " m"; ?></p>
<?php foreach($desc as $row){ ?>
<p class="list_pasi"><i>Pasul <?php echo $nr; ?></i>: <?php echo $desc[$k]; ?></p>
<?php $k++; $nr++;
} ?>
</li>
<?php } ?>
食谱:
食谱步骤:
配方成分: