Ver Mensaje Individual
  #12 (permalink)  
Antiguo 26/11/2015, 17:12
pilucho
 
Fecha de Ingreso: noviembre-2004
Ubicación: NULL
Mensajes: 655
Antigüedad: 20 años, 2 meses
Puntos: 6
Respuesta: Sumar el total de dos campos

LO deje asi y suma una cantidad que no esta en PO ni en IV

suma de PO

Código PHP:
Ver original
  1. <?php  
  2.         if (isset($_GET['route']))  $route = $_GET['route'];
  3.         if (isset($_GET['drug_id']))    $cid = $_GET['drug_id'];
  4.         $conexion = mysqli_connect($dbhost,$dbuser,$dbpass,$dbdatabase) or die ('error');   // Conexión
  5.         if (!$conexion) {   die("Error de conexión: " . mysqli_connect_error());    }
  6.         $sql = "SELECT drug_id,
  7.        SUM(case route when 'po' then `count` else 0 end) totalPO,
  8.        SUM(case route when 'iv' then `count` else 0 end) totalIV,
  9.         (SUM(case route when 'po' then `count` else 0 end)) + SUM(case route when 'po' then `count` else 0 end))) AS Total
  10.         FROM core_reports_antiinfectives
  11.         ";
  12.         $result = mysqli_query($conexion, $sql);
  13.         if (mysqli_num_rows($result) > 0) {
  14.            
  15.         $coma=0;   
  16.         while($row = mysqli_fetch_assoc($result)) {
  17.         ?>
  18.             <?php echo $Total = $row["Total"]; ?>
  19.            
  20.             <? if ($coma < (mysqli_num_rows($result) - 1)){echo ','; $coma++; }  ?>
  21.      
  22.         <?  }  } mysqli_close($conexion); ?>