tengo la siguiente consulta estoy usando php:
<?php
$rendillan="SELECT id_repa,tipo_rep_equiv,nro_reparacion,km_repa,tipo_dano,zona_repa,duracion,COUNT(*) as id_repa FROM reparacion where nro_cliente_repa='$llantap' group by nro_reparacion";
$rent=mysql_query($rendillan,$con);
?>
<table border='1'>
<tr>
<th>Repair Number</th>
<th>Life Repaired</th>
<th>Type Repair</th>
<th>Type of Damage</th>
<th>Damage location</th>
<th>Fail</th>
<th>Repair Duration</th>
</tr>
<?php
while(($rentl=mysql_fetch_assoc($rent))>0)
{
$tipo=$rentl['tipo_dano'];
?>
<tr>
<td><b><?php echo $rentl['nro_reparacion']; ?></b></td>
<td><b><?php echo round($rentl['km_repa']); ?></b></td>
<td><b><?php echo $rentl['tipo_rep_equiv']; ?></b></td>
<td><b><?php echo $rentl['tipo_dano']; ?></b></td>
<td><b><?php echo $rentl['zona_repa']; ?></b></td>
<?php if($tipo=='Falla de Reparacion')
{
echo "<td style='background-color:red;'><b>SI</b></td>";
}
else{
echo "<td style='background-color:#ffffff;'><b>NO</b></td>";
} ?>
<td><b>Aquí va la variable que deseo calcular</b></td>
</tr>
<?php
}
?>
</table>
Ahora la columna de la tabla que se llama -Repair Duration- allí debo calcular cuanto duro cada reparación.
Y se calcula de la siguiente manera:
Registro 1 = 24824 (Esta variable es: km_repa) registro 2 = 49992 (Esta variable es: km_repa)
49992-24824 = 25168
como puedo hacer para que dentro del while haga ese calculo y luego imprimir la variable en la columna -Repair Duration-.
Ya intente restando la variable km_repa con la misma pero siempre me da 0
la idea es recorrer el while y que me vaya dando el valor correcto.
Cualquier ayuda es de gran utilidad.
Ya realice los ajustes quedando la consulta de esta manera:
<?php
$rendillan="SELECT id_repa,tipo_rep_equiv,nro_reparacion,km_repa,tipo_dano,zona_repa,duracion,COUNT(*) as id_repa FROM reparacion where nro_cliente_repa='$llantap' group by nro_reparacion";
$rent=mysql_query($rendillan,$con);
?>
<table border='1'>
<tr>
<th>Repair Number</th>
<th>Life Repaired</th>
<th>Type Repair</th>
<th>Type of Damage</th>
<th>Damage location</th>
<th>Fail</th>
<th>Repair Duration</th>
</tr>
<?php
$km_repa = 0;
$resultado = 0;
while(($rentl=mysql_fetch_assoc($rent))>0)
{
$tipo=$rentl['tipo_dano'];
$km_repa = $rentl['km_repa'];
$resultado = $km_repa - $resultado; //Almacenas la resta
?>
<tr>
<td><b><?php echo $rentl['nro_reparacion']; ?></b></td>
<td><b><?php echo round($rentl['km_repa']); ?></b></td>
<td><b><?php echo $rentl['tipo_rep_equiv']; ?></b></td>
<td><b><?php echo $rentl['tipo_dano']; ?></b></td>
<td><b><?php echo $rentl['zona_repa']; ?></b></td>
<?php if($tipo=='Falla de Reparacion')
{
echo "<td style='background-color:red;'><b>SI</b></td>";
}
else{
echo "<td style='background-color:#ffffff;'><b>NO</b></td>";
} ?>
<td><b>Aquí va la variable que deseo calcular</b></td>
</tr>
<?php
}
?>
</table>
Y la columna da como resultado:
Creo que me esta dando mal los resultados.