Ver Mensaje Individual
  #4 (permalink)  
Antiguo 25/02/2014, 12:16
LiveTechno
 
Fecha de Ingreso: junio-2011
Ubicación: Barcelona
Mensajes: 212
Antigüedad: 12 años, 11 meses
Puntos: 17
Respuesta: Sumar totales en horizontal y vertical

Aunque hay otros metodos mejores y mas optimizados para que te hagas una idea de las funciones que tienes que utilizar serian:


Código PHP:
Ver original
  1. <?php
  2. $datos=mysql_query($consulta,$conexion);
  3. $tr_empresas="";
  4. $gastos_vertical_1 = array();
  5. $gastos_vertical_2 = array();
  6. $gastos_vertical_3 = array();
  7. $gastos_vertical_4 = array();
  8. $gastos_vertical_5 = array();
  9. $gastos_vertical_6 = array();
  10. $gastos_vertical_7 = array();
  11. $gastos_vertical_8 = array();
  12. $gastos_vertical_9 = array();
  13. $gastos_vertical_10 = array();
  14. $gastos_vertical_11 = array();
  15. $gastos_vertical_12 = array();
  16. while($row = mysql_fetch_assoc($datos)){
  17. $gastos_horizontal = array($row['01'],$row['02'],$row['03'],$row['04'],$row['05'],$row['06'],$row['07'],$row['08'],$row['09'],$row['10'],$row['11'],$row['12']);
  18. array_push($gastos_vertical_1, $row['01');
  19. array_push($gastos_vertical_2, $row['02');
  20. array_push($gastos_vertical_3, $row['03');
  21. array_push($gastos_vertical_4, $row['04');
  22. array_push($gastos_vertical_5, $row['05');
  23. array_push($gastos_vertical_6, $row['06');
  24. array_push($gastos_vertical_7, $row['07');
  25. array_push($gastos_vertical_8, $row['08');
  26. array_push($gastos_vertical_9, $row['09');
  27. array_push($gastos_vertical_10, $row['10');
  28. array_push($gastos_vertical_11, $row['11');
  29. array_push($gastos_vertical_12, $row['12');
  30. $tr_empresas.="
  31.    <tr>
  32.        <td align='center'>".$row['categoria']."</td>
  33.        <td align='center'>".$row['01']."</td>
  34.        <td align='center'>".$row['02']."</td>
  35.        <td align='center'>".$row['03']."</td>
  36.        <td align='center'>".$row['04']."</td>
  37.        <td align='center'>".$row['05']."</td>
  38.        <td align='center'>".$row['06']."</td>
  39.        <td align='center'>".$row['07']."</td>
  40.        <td align='center'>".$row['08']."</td>
  41.        <td align='center'>".$row['09']."</td>
  42.        <td align='center'>".$row['10']."</td>
  43.        <td align='center'>".$row['11']."</td>
  44.        <td align='center'>".$row['12']."</td>
  45.        <td align='center'>".array_sum($gastos_horizontal)."</td>
  46.   </tr>
  47.    <tr>
  48.        <td><br></td>
  49.    </tr>";
  50. }
  51. ?>

Es para que veas como serias mas o menos y que funciones tienes que utilizar para sumar todas las entradas del array utiliza array_sum

Un saludo.
__________________
Twitter: @ed33x