Ver Mensaje Individual
  #7 (permalink)  
Antiguo 26/03/2021, 20:11
pilucho
 
Fecha de Ingreso: noviembre-2004
Ubicación: NULL
Mensajes: 652
Antigüedad: 19 años, 5 meses
Puntos: 6
Respuesta: sumar el total de todo los items

Cita:
Iniciado por tuadmin Ver Mensaje
por que llamas variables q no existen??

$sum += $row['total_saleing_price'];
$sub += $row['total_buying_price'];

si tu $row tiene total_buy_price y total_s_price
no existe esa variable es solo una palabra:

de este modo tampoco suma solo me da el total de cada item mas no el total de todo
Código PHP:
Ver original
  1. $result = $conn->query($sql);
  2.             if ($result->num_rows > 0) {
  3.             // AQUI    
  4.             $total_del_todo_ganancias = 0;
  5.             $total_saleing_price = 0;
  6.             $total_buying_price = 0;
  7.             while($row = $result->fetch_assoc()) {
  8.             /* O AQUI IGUAL NO SUMA EL TOTAL DE TODO
  9.             $total_del_todo_ganancias = 0;
  10.             $total_saleing_price = 0;
  11.             $total_buying_price = 0;
  12.             */
  13.             ?>
  14.  
  15.             <?php
  16.             // INTENTO 2
  17.             $total_saleing_price += $row['total_saleing_price'];
  18.             $total_buying_price += $row['total_buying_price'];
  19.             $ganancias = $total_saleing_price - $total_buying_price;
  20.             echo "-> $ganancias  <-"; // EL MISMO TOTAL DE CADA ITEM'S y NO el total de TODO
  21.             ?>