[QUESTION Pt.3] - Two Query loops in one.
Posted: Tue Aug 28, 2007 12:59 am
Go Down for Question 2.
Hey Guys,
I have two tables in the database, one is the product information, and if the product is in a food group, a nutrition guide table is also used.
What I need is to have the Product information loop in a while statement, so it shows all products, and at the same time, it has to pull all rows from the nutrition guide table that refer to a particular food when it gets to that food product, so esentially, it is a loop inside another loop.
Eg.
So, using the example, the loop would first bring out APPLE, then loop the nutrtional guide table to bring out FAT and then SUGAR and then onto ORANGE in the product table again.
Does anyone know how I could do this?
Hey Guys,
I have two tables in the database, one is the product information, and if the product is in a food group, a nutrition guide table is also used.
What I need is to have the Product information loop in a while statement, so it shows all products, and at the same time, it has to pull all rows from the nutrition guide table that refer to a particular food when it gets to that food product, so esentially, it is a loop inside another loop.
Eg.
Code: Select all
+----------+----------+
| id | product |
+----------+----------+
+----------+----------+
| 1 | apple |
+----------+----------+
| 2 | orange |
+----------+----------+Code: Select all
+----------+----------+----------+----------+----------+
| id | prodid | cat | serving | whole |
+----------+----------+----------+----------+----------+
+----------+----------+----------+----------+----------+
| 1 | 1 | fat | .5g | 1.5g |
+----------+----------+----------+----------+----------+
| 2 | 1 | sugar | 20g | 40g |
+----------+----------+----------+----------+----------+Does anyone know how I could do this?