如何计算行数,其中我的id位于其中一个文件中,该字段是json对象:
async/await
示例我的id = 15,我可以看到在第一组星期一我可以看到15,这意味着有1行具有该值。现在我有200行,只有150行我有id = 15所以我想计算并显示数字150
{
"Monday":{"1":"15","2":"27","3":"74","4":"47","5":"42","6":"53"},
"Tuesday":{"1":"11","2":"28","3":"68","4":"48","5":"43","6":"82"},
"Wednesday":{"1":"13","2":"29","3":"69","4":"49","5":"44","6":"54"},
"Thursday":{"1":"14","2":"30","3":"70","4":"50","5":"45","6":"55"},
"Friday":[]
}
$getMenus = $db->next_record($db->query("SELECT COUNT(*) as total, product_menu_meals FROM product_menus WHERE 1"));
$getMeals = (json_decode($getMenus['product_menu_meals'], true));
if(in_array($mainMeal['meal_id'], array_filter($getMeals['Monday'])) ||
in_array($mainMeal['meal_id'], array_filter($getMeals['Tuesday'])) ||
in_array($mainMeal['meal_id'], array_filter($getMeals['Wednesday'])) ||
in_array($mainMeal['meal_id'], array_filter($getMeals['Thursday'])) ||
in_array($mainMeal['meal_id'], array_filter($getMeals['Friday']))){echo $getMenus['total'];};
答案 0 :(得分:0)
<?php
$MenusArray = array();
$arrayMenus = array();
$codeQuery = $db->query("SELECT * FROM product_menus;");
$codeQuery2 = "SELECT COUNT(*) as total FROM product_menus WHERE";
$i = 0;
while($followingdata = $db->next_record($codeQuery)){
$arrayMenus[] = (json_decode($followingdata['product_menu_meals'], true));
if(in_array($mainMeal['meal_id'], array_filter($arrayMenus[$i]['Monday']))){$codeQuery2 .= " product_menu_id = '".$followingdata['product_menu_id']."' OR";}
if(in_array($mainMeal['meal_id'], array_filter($arrayMenus[$i]['Tuesday']))){$codeQuery2 .= " product_menu_id = '".$followingdata['product_menu_id']."' OR";}
if(in_array($mainMeal['meal_id'], array_filter($arrayMenus[$i]['Wednesday']))){$codeQuery2 .= " product_menu_id = '".$followingdata['product_menu_id']."' OR";}
if(in_array($mainMeal['meal_id'], array_filter($arrayMenus[$i]['Thursday']))){$codeQuery2 .= " product_menu_id = '".$followingdata['product_menu_id']."' OR";}
if(in_array($mainMeal['meal_id'], array_filter($arrayMenus[$i]['Friday']))){$codeQuery2 .= " product_menu_id = '".$followingdata['product_menu_id']."' OR";}
$i++;
}
$codeQuery2 = substr($codeQuery2,0,-2);
$queryMenus = $db->next_record($db->query($codeQuery2));
echo $queryMenus['total'];
?> Menus