I want to take the percentage of two numbers that I store in two variables, the first variable is my delivery counter on time and the second is my delivery counter out of time, the sum is done correctly but I do not know how to get the percentage of that total, I know that it's something very simple, with a rule of three basic arithmetic, but I'm interested in passing it to the code.
<?php
include('conexion.php');
$fecha1=$_POST['finicio'];
$fecha2=$_POST['ffin'];
$contat=0;$contft=0;
$query=mysql_query("SELECT factura, fechafactura, cliente, hrasalida, hraentrega, hrallegada,fechaentrega,horarecibido, chofer, vehiculo, direccion from facturacion where estatus='ENTREGA DOMICILIO' AND fechafactura >= '$fecha1' AND fechafactura <= '$fecha2' order by fechafactura DESC LIMIT 70");
$cont=mysql_num_rows($query);
if ($cont>0)
{
while ($array=mysql_fetch_array($query))
{
$fefac=$array[1];
$feent=$array[6];
$recfac=$array[7];
$hrini=$array[3];
$hrfin=$array[4];
$diferencias = strtotime($hrfin) - strtotime($hrini);
$mins=$diferencias/60;
//HORARIO DE 8:30 A 1:30
$horalimite=strtotime("18:00:00");
$hentrega=strtotime($hrfin);
$hora1=strtotime("08:30:00");
$hora2=strtotime("13:30:00");
$hrecfac=strtotime($recfac);
//HORARIO DE 1:30 A 18:00
$hora3=strtotime("13:31:00");
$hora4=strtotime("18:00:00");
/*$hora5=("18:00:00");
$horali=date($hora5);
$horalimite2=date('H:i:s', strtotime($horali.' +19 hours'.' +30 minutes'));
*/
$horali=date("18:00:00");
$HL=strtotime($horali);
$horalimite2=date("H:i:s",mktime(date("H",$HL)+19,date("i",$HL)+30,date("s",$HL)));
$f=date($fefac);
$fechalimite=date('Y-m-d', strtotime($f.' +1 days'));
$dia=date($fefac);
$S=date("w", strtotime($dia));
//HORARIO DE SABADO
$hora5=strtotime("08:30:00");
$hora6=strtotime("14:00:00");
$f=date($fefac);
$fechalimite2=date('Y-m-d', strtotime($f.' +2 days'));
if($S!="6")
{
if($hrecfac>=$hora3 and $hrecfac<=$hora4)
{
if($hentrega>strtotime($horalimite2) or strtotime($feent)>strtotime($fechalimite))
{
$status="<label class='bg2'>FUERA DE TIEMPO</label>";
$contft=$contft+1;
}
else
{
$status="<label class='bg1'>A TIEMPO</label>";
$contat=$contat+1;
}
}
else if($hrecfac>=$hora1 and $hrecfac<=$hora2)
{
if($hentrega>$horalimite or strtotime($feent)>strtotime($fefac))
{
$status="<label class='bg2'>FUERA DE TIEMPO</label>";
$contft=$contft+1;
}
else
{
$status="<label class='bg1'>A TIEMPO</label>";
$contat=$contat+1;
}
}
}
else
{
if($hrecfac>=$hora5 and $hrecfac<=$hora6)
{
if($hentrega>$horalimite or strtotime($feent)>strtotime($fechalimite2))
{
$status="<label class='bg2'>FUERA DE TIEMPO</label>";
$contft=$contft+1;
}
else
{
$status="<label class='bg1'>A TIEMPO</label>";
$contat=$contat+1;
}
}
}
echo'<tr><td>'.$array[0].'</td><td>'.$array[1].'</td><td>'.$array[2].'</td><td>'.$array[3].'</td><td>'.$array[4].'</td><td>'.$array[5].'</td><td>'.$array[6].'</td><td>'.$array[7].'</td><td>'.$array[8].'</td><td>'.$array[9].'</td><td>'.$array[10].'</td><td>'.$mins.'min'. '</td><td>'.$status.'</td></tr>';
}
}
else
{
echo'<tr><td>No hay registros</td></tr>';
}
echo '<table>';
/***************************************TERMINA FACTURAS*/
?>