MySql count query problem[solved]
Posted: Tue Jan 11, 2005 4:28 am
I got a MYSql table with Recipes. I got 3 ENUM (TRUE,FALSE) Flags which kind of diet the recipe can be used for. Duplicate True's can be occuring.
Now I want to count the recipes for each of the 3 possible diets
A php solution is
but I like to learn more about MYSQL. Is there a way to put above 3 queries into 1 getting either 3 rows with the count values or 1 row with all 3 values.
Now I want to count the recipes for each of the 3 possible diets
Code: Select all
SELECT count(Recipe_ID) FROM Recipes WHERE softdiet = 'TRUE';
SELECT count(Recipe_ID) FROM Recipes WHERE mediumdiet = 'TRUE';
SELECT count(Recipe_ID) FROM Recipes WHERE harddiet = 'TRUE';Code: Select all
$msl="SELECT softdiet, mediumdiet, harddiet FROM Recipes";
$result=mysql_query($msl);
while($row=mysql_fetch_assoc($result)){
if($rowї'softdiet']=="TRUE"){
$soft++;
}
if($rowї'mediumdiet']=="TRUE"){
$medium++;
}
if($rowї'harddiet']=="TRUE"){
$hard++;
}
}