subtract values from two php functions

1

I'm adding two fields and everything works fine. The problem is that I do not know how to subtract those two values to find the difference, because the values of Cant. Bet and Cant. Won calculate them by means of a function each and I want to show the difference in the red box of the image. / p>

Functions with which I sumo

public static function sumar($apostado) {
    	$sql="select SUM($apostado) AS suma FROM ".self::$tablename;
		$query = Executor::doit($sql);
		return Model::one($query[0],new apuestaData());
	}

    public static function sumarg($ganado) {
    	$sql="select SUM($ganado) AS sumag FROM ".self::$tablename;
		$query = Executor::doit($sql);
		return Model::one($query[0],new apuestaData());
	}

I create the table and load the data

<div class="box-body">

  <?php if (count($reporte)>0): ?>
    <table class="table table-bordered table-hover">
      <thead id="cabe">
        <th>Cant. Apostado</th>
        <th>Cant. Ganado</th>
        <th>Ganancias</th>
      </thead>   
<tr>
<td><?php $apostadoSuma = apuestaData::sumar("apostado");
      echo $apostadoSuma->suma;?>
</td>
<td><?php $apostadoSuma = apuestaData::sumarg("ganado");
      echo $apostadoSuma->sumag;?>
</td>                       
</tr>   
</table>
  <?php else: ?>
    <p class="alert alert-warning">No Se Encontraron Datos</p>
  <?php endif; ?>

</div>

Someone can help me ...

    
asked by Horus 02.02.2018 в 20:00
source

1 answer

0

You only need to subtract what you have won with the bet:

<div class="box-body">
  <?php if (count($reporte)>0): ?>
    <table class="table table-bordered table-hover">
      <thead id="cabe">
        <th>Cant. Apostado</th>
        <th>Cant. Ganado</th>
        <th>Ganancias</th>
      </thead>
      <tbody>
        <tr>
          <td><?php $apostadoSuma = apuestaData::sumar("apostado");
            echo $apostadoSuma->suma;?>
          </td>
          <td><?php $apostadoSumag = apuestaData::sumarg("ganado");
            echo $apostadoSumag->sumag;?>
          </td>
          <td><?php $ganacia = $apostadoSumag->sumag - $apostadoSuma->suma;
            echo $ganacia; ?>
          </td>
        </tr>
      <tbody>
    </table>
  <?php else: ?>
    <p class="alert alert-warning">No Se Encontraron Datos</p>
  <?php endif; ?>
</div>
    
answered by 02.02.2018 / 20:14
source