Query inside a 'loop'.
Submitted by Onthrax on Fri, 2006-08-18 13:28.
ezSQL
I'm a bit experimenting with (ez)SQL and was wondering if there is an easy way of 'merging' two queries into a single one, so I will have 1 query to the db, instead of 1 for each ingredient.
$ingredients = $db->get_results("SELECT ingredient_title FROM Data_ingredients");
foreach ( $ingredients as $ingredient) {
$var = $db->get_var("SELECT count(*) FROM Data_meals WHERE mainingredient = '".$ingredient->ingredient_title."'");
echo $ingredient->ingredient_title." ".$var."";
}
The above script reads all ingredients from the ingredients table, and should count the number of times the ingredient has been used as main ingredient for a meal.
Hope someone can help me..
Cheers!
