Thank you for replying so quickly. I've taken your advice and tried to make my page work, but I am still having some problems fitting your code into mine correctly.
Here is my revised MySQL table structure:
recipes:
recipe_id
recipe_name
recipe_instructions
recipe_image
ingredients:
ingredient_id
recipe_id
ingredient_name
Now here is an abbreviated real life example:
recipes:
1
Cool as a Cucumber Soup
Blend well.
soup_cuke.jpg
ingredients:
1
1
2-3 large cucumbers
2
1
1 c tomatoes
3
1
1 c lemon juice
4
1
1/2 c onion
5
1
1 t sea salt
Now here is an example of my code to show this recipe:
<!--mysql_connect--code here-->
<!--mysql_select_db--code here-->
<?php
// Request the text of all the recipes
$result = @('SELECT recipe_name, recipe_instructions, recipe_image FROM recipes');
if (!$result) {
exit('<p>Error performing query: ' . mysql_error() . '</p>');
}
while ($row = mysql_fetch_array($result)) {
$recipe_name=$row['recipe_name'];
$recipe_ingredients=$row['recipe_ingredients'];
$recipe_instructions=$row['recipe_instructions'];
$recipe_image=$row['recipe_image'];
$ingredients_name=$row['ingredients_name'];
echo_
?>
<div class="recipe">
<h1 class="title"> <?php echo "$recipe_name"; ?></h1>
<div align=center><img src="images/r/ <?php echo "$recipe_image" ?>"></div>
<div class="instr">
<div class="ing">
<h1>Ingredients</h1>
<p> <?php echo "$recipe_ingredients" ?> </p>
</div>
<h1 class="ingredients">Instructions</h1>
<p> <?php echo "$recipe_instructions" ?> </p>
<div style="clear:both"></div>
</div>
</div>
<?php ;
}
?>
Now in your reply you said to use the following to select the ingredients
select * from recipe r left join ingredient i on i.recipe_id=r.recipe_id
How do I add this to my SELECT command? This is how I've been doing it, but it is not working:
$result = @('SELECT recipe_name, recipe_instructions, recipe_image, ingredients_name FROM recipes, ingedients, recipe r left join ingredient i on i.recipe_id=r.recipe_id');
Where did the i and r come from and what do they represent? I am guessing they represent the table names, but then shouldn't it have been:
SELECT * FROM recipe_id.recipes LEFT JOIN recipe_id.ingredients ON ingredients.recipe_id=recipes_recipe.id
Then I am left with the puzzle of fitting it into my echo statement. This is my proposed new structure:
echo_
?>
<div class="recipe">
<h1 class="title"> <?php echo "$recipe_name"; ?></h1>
<div align=center><img src="images/r/ <? php echo "$recipe_image" ?>"></div>
<div class="instr">
<div class="ing">
<h1>Ingredients</h1>
<p> <?php echo "$ingredients_name" ?> </p>
</div>
<h1 class="ingredients">Instructions</h1>
<p> <?php echo "$recipe_instructions" ?> </p>
<div style="clear:both"></div>
</div>
</div>
<?php ;
}
?>
I feel like I am almost there, I am just not grasping a major concept. If it is blatantly obvious to you what I am doing wrong, could you let me know? Thanks.