[英]PHP foreach while loop how to sum output
查询返回按运算符分组的元素总和(由复选框选择)。
如何总结所有这些价值? 我尝试使用 array_sum() 但没有用,或者我没有正确使用这个函数。 谢谢
<?php
if(isset($_POST['delete']))
{
$ziua=$_POST["date"];
}
else
{
$ziua=date('Y-m-d');
}
if(isset($_POST['delete']))
{//check to see if the delete button has been pressed
if(isset($_POST['box']))
{ //check to see if any boxes have been checked
$num = 0;//used to count the number of rows that were deleted
$box = $_POST['box'];
foreach ($box as $key =>$val)
{ //loop through all the checkboxes
$num++;
$sqldel=" SELECT U.username , SUM(L.geometrie1) A from list L,users U where L.user_id='$val'
and L.date_posted like '%$ziua%' AND L.user_id=U.id group by U.username ";//delete any that match id
$resdel=mysql_query($sqldel);//send the query to mysql
while($row = mysql_fetch_array($resdel))
{
Print "<tr>";
Print '<td align="center">'. $row['0']. "</td>";
Print '<td align="center">'. $row['1']. "</td>";
Print "</tr>";
}
}
}
}
?>
<!-- end snippet -->
在循环之前添加
$total=0;
在你的循环中添加
$total += $row[1];
然后在循环后回显
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.