mercredi 23 septembre 2015

PHP foreach while loop how to sum output

Query returns sum of elements group by operator (selected by checkbox).

How to sum up all that values? I tried using array_sum() but didn't worked or maybe i am not using this function correct. Thank you

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

                }


     }

}
   }


?>




Aucun commentaire:

Enregistrer un commentaire