查询按运算符(按复选框选择)返回元素总和。
如何总结所有价值观?我尝试使用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 -->
答案 0 :(得分:0)
在循环添加
之前 $total=0;
在你的循环中添加
$total += $row[1];
然后在循环后回显