gpt4 book ai didi

php - 如何计算行数,Json

转载 作者:行者123 更新时间:2023-11-29 22:22:22 26 4
gpt4 key购买 nike

如何计算行数,其中我的 id 位于其中一个字段中,并且该字段是 json 对象:

{
"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'];};

例如,我的 id = 15,我可以看到在第一组星期一我可以看到 15,这意味着有 1 行具有该值。现在我有 200 行,只有 150 行中有 id = 15,所以我想计算并显示数字 150

<小时/>
>  <?php 
> $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'];};
> ?> Menus

最佳答案

<?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

关于php - 如何计算行数,Json,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30594419/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com