I have a table in my database that is filled with equations in the form of recipies. Each recipie has 1 to 8 ingredients. Every possible ingredient for all of the recipies as well as the RESULTS of every possible recipie is stored in ANOTHER table. Lets call one table Recipies, and the other, Foods. I am attempting to retrieve the cost of every recipie result, as well as the cost of every ingredient, so I can compute the PROFIT MARGIN of a given recipie. I want to display all parts of every recipie and all costs of every food for the associated recipie on my web page.
I can display the equations themselves, and also all of the food items. But I can't seem to draw the ingredient costs when I need them...
Here is the syntax I use to display the recipie, and the cost of the result:
Code: Select all
$sql = 'SELECT Recipies.ItemName AS Result, Recipies.PrimarySkill AS Guild,
.
. //ALL the ingredients and the quantity of each ingredient required.
.
Recipies.QuantityEight
FROM Items, Recipies
WHERE (Items.ItemName = Recipies.ItemName) AND (Items.Stack = 1)';
$result = mysql_query($sql);
echo "<br>";
while ($row = mysql_fetch_assoc($result)){
echo $rowї'Result'];
.
.//I echo the results so I can see what's going on
.
echo $rowї'Quantity'];
}
The problem I'm having is using the DATA from an existing table, to LOCATE the data from ANOTHER table that I want to retrieve and compute. It's almost like I need nested queries to get this done, but mysql_query() won't accept a $var (from the first query) in the WHERE portion. EG:
Code: Select all
$Internal = 'SELECT Items.ItemName ...
FROM Items, Recipies
WHERE (ItemName = $IngredientOne) and (Stack = 1); //Here...
$Funky = mysql_query($Interal)'; //This returns nothing to $Funky
while ($Plow = mysql_fetch_assoc($Funky))
{...}
I could never get the above to work. Any ideas on how to access multiple rows from one table, when those rows are chosen by data contained in a second table? (Remember, I need to take all these different values and add/subtract them according to the said equation then display them to a web page.)