Problems Looping Through A Db Item

Only 1 ingredient displays in the loop

Page 1 of 1

7 Replies - 2820 Views - Last Post: 05 January 2005 - 07:47 AM Rate Topic: -----

#1 wannab  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 08-December 04

Problems Looping Through A Db Item

Posted 08 December 2004 - 08:01 AM

I have tried everything and read a lot about outer joins. And this is what I get-
Here is the complete code with the output at the bottom:

<cfparam name="URL.recNo" default="1">
<cfparam name="URL.recIng" default="0">
<cfset displayRecordNumber=URL.recNo>
<cfset nextRecipe=displayRecordNumber+1>
<cfset previousRecipe=displayRecordNumber-1>
<cfset displayRecipeIng=URL.recIng+1>
<!---QUERY DATABASE TO OUTPUT SELECT INFORMATION--->
<cfquery name="getRecipes">
SELECT DISTINCT Ingredients.IngName,
Measurements.MeasurementName, RecipeIngredients.Amount,
Recipes.RecipeID, Recipes.RecipeName, Recipes.Directions,
Recipes.Notes FROM Recipes, RecipeClass, Measurements,
RecipeIngredients, Ingredients
WHERE RecipeIngredients.RecipeID=Recipes.RecipeID AND
Ingredients.IngID=RecipeIngredients.IngID AND
Measurements.MeasurementID=RecipeIngredients.MeasurementID
AND RecipeClass.RecipeClassID=Recipes.RecipeClassID
</cfquery>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0

Transitional//EN">
<html>
<head>
<title>Recipe Details</title>
<style>
TD {
font-family : "Trebuchet MS";
}
H3 {
font-family : "Trebuchet MS";
}
</style>
</head>
<body bgcolor="#99CCFF">
<hr align="center" color="Black" width="300">
<h3 align="center">Recipe Details Intranet Application</h3>
<hr align="center" color="Black" width="300">
<!---LOOPS TO CYCLE THROUGH EACH RECIPE'S
INFORMATION--->
<cfloop query="getRecipes" startrow="#displayRecordNumber#"
endrow="#displayRecordNumber#">
<table align="center" border="1" bordercolor="Black"
width="800">
<tr>
<td >
<!---OUTPUT STATEMENTS TO DISPLAY RECIPES'
INFORMATION--->
<cfloop index="IngName" list="#IngName#">
<cfoutput>#Amount# #MeasurementName# #IngNa
me#</cfoutput></td></cfloop><br><br>
<cfoutput><td><b>#RecipeName#</b><br><br>
#Directions#<br><br>
#Notes#<br><br></td></cfoutput>
</td>
</tr>
</cfloop>
</table>

Here is what the output looks like

(Ingredients)1 box 7 oz. Moist Deluxe Butter Recipe cake mix
"no oher ingredients"

(Recipe Name)Apple Tea Cake

(Directions)1. Preheat oven to moderate 350F. Brush a shallow 8 inch round cake pan with melted butter or oil. Line base with waxed paper; grease paper. 2. Reserve 2 tablespoons of the tea cake mix for topping. Place the remaining contents of cake mix into small mixing bowl with butter, egg, juice and apple. Using electric beaters, beat ingredients together on low speed for 2 minutes or until mixture is smooth. Spread mixture over base of prepared pan; smooth surface. 3. Place cinnamon, sugar, reserved cake mix, coconut and extra butter in small mixing bowl. Using fingertips, rub butter into mixture for 1 minute or until mixture is a coarse, crumbly texture; add almonds. Sprinkle the mixture over cake batter, bake 30 minutes or until skew comes out clean when inserted in center of cake. Leave cake in pan 5 minutes before turning onto wire rack to cool. Dust with confectioners' sugar and serve warm or cold with custard sauce or cream.

Is This A Good Question/Topic? 0
  • +

Replies To: Problems Looping Through A Db Item

#2 Amadeus  Icon User is offline

  • g+ + -o drink whiskey.cpp
  • member icon

Reputation: 248
  • View blog
  • Posts: 13,507
  • Joined: 12-July 02

Re: Problems Looping Through A Db Item

Posted 08 December 2004 - 10:42 AM

Is it a ColdFusion loop problem, or a query problem? run that query on the command line, and see what it brings back for ingredients. Your 'WHERE' clause has a lot of AND conditions, and so may be limiting the results.
Was This Post Helpful? 0
  • +
  • -

#3 supersloth  Icon User is offline

  • serial frotteur - RUDEST MEMBER ON D.I.C.
  • member icon


Reputation: 4513
  • View blog
  • Posts: 28,416
  • Joined: 21-March 01

Re: Problems Looping Through A Db Item

Posted 08 December 2004 - 10:59 AM

also, what is the output supposed to be compared to what your getting now?
Was This Post Helpful? 0
  • +
  • -

#4 wannab  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 08-December 04

Re: Problems Looping Through A Db Item

Posted 08 December 2004 - 11:07 AM

The output is supposed to be exactly what it is at the bottom of the code, except it is supposed to show all of the ingredients for that recipe.

EX: 1 box 7 oz. Moist Deluxe Butter Recipe cake mix
2 eggs
1/2 cup sugar, etc.
Was This Post Helpful? 0
  • +
  • -

#5 skyhawk133  Icon User is offline

  • Head DIC Head
  • member icon

Reputation: 1877
  • View blog
  • Posts: 20,284
  • Joined: 17-March 01

Re: Problems Looping Through A Db Item

Posted 09 December 2004 - 08:37 AM

In the debugging information, how many records does your query return, also, if you do a cfdump what does the query look like?
Was This Post Helpful? 0
  • +
  • -

#6 wannab  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 08-December 04

Re: Problems Looping Through A Db Item

Posted 09 December 2004 - 02:20 PM

Skyhawk,

When I use the cfdump tag, it returns over 200 records, each recipe ingredient with directions for each specific cake. What I am trying to do is return each recipe ingredient specific to each recipe with the recipe's directions. It is something wrong with displaying a list of ingredients for each recipe, but I don't know what?:huh:
Was This Post Helpful? 0
  • +
  • -

#7 skyhawk133  Icon User is offline

  • Head DIC Head
  • member icon

Reputation: 1877
  • View blog
  • Posts: 20,284
  • Joined: 17-March 01

Re: Problems Looping Through A Db Item

Posted 09 December 2004 - 02:26 PM

Hmmm, I'm in PHP mode right now, but I'll try and figure out what's causing it later.

If I were to do this, and I might be totally wrong here with the way you are doing your code, but I would pull back the recipe AND ingredients in 1 query (which I think you are already doing), then I would use a <cfoutput query="getRecipes" group="RecipeID"> which will group the output by the recipe then display all the ingredients under it.
Was This Post Helpful? 0
  • +
  • -

#8 jsteenberge  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 05-January 05

Re: Problems Looping Through A Db Item

Posted 05 January 2005 - 07:47 AM

i would not use the loop. like skyhawk stated

<cfoutput query="querynamehere"> should take care of all your needs ... or move the cfloop inside the cfoutputs. that may fix it ... but the first recomendation should work
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1