gpt4 book ai didi

PHP 和 MySql - 数组 foreach

转载 作者:太空宇宙 更新时间:2023-11-03 11:01:14 24 4
gpt4 key购买 nike

<分区>

我想从数据库运行一个 foreach 循环,但我不知道如何开始。我有一个从 while 循环生成的数组:

    /* mysql query for geting leave_type ID */

$leaveType = mysql_query("
SELECT `leave`.leave_type_id_leave_type,
`leave`.staff_leave_application_staff_id_staff,
`leave`.date,
`leave`.date_updated,
`leave`.active
FROM `leave`
WHERE `leave`.staff_leave_application_staff_id_staff = $iid
GROUP BY `leave`.leave_type_id_leave_type
");

/* Now put all leave Type ID in an array */

echo "<table>";
$types = array();
while($leaveFW = mysql_fetch_array( $leaveType )){
$types[] = $leaveFW['leave_type_id_leave_type'];
}
print_r($types);

现在我想运行一个 foreach 循环,它将在下面的代码中查询数组中的每个 ID。 :

$leaveQ = mysql_query("SELECT Count(*) as total, monthname(date) as 
month FROM `leave`
WHERE `leave`.staff_leave_application_staff_id_staff = $iid
and `leave`.leave_type_id_leave_type = $type");

我想在 foreach 循环中显示 $leaveQ['month']$leaveQ['total']

可能是我这样的 foreach,但是如何获取 $type['month']$type['total'] :

foreach ($types as $type)
{
$leaveQ = mysql_query("SELECT Count(*) as total, monthname(date) as month
FROM `leave` WHERE `leave`.staff_leave_application_staff_id_staff = $iid
and `leave`.leave_type_id_leave_type = $type");
}

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