1
I need to make a calculation as a result that I get from the query where he made only a division of the total value of a person by the average that was obtained from all. See the image:
I don’t know if it’ll help, but part of the code is like this:
$idservico = 0;
$idservicoAnterior = -1;
$totalAtendimentos = 0;
$quantidadePessoas = 0;
$media = 0;
if(empty($mes) || empty($ano))
{
echo "<script> alert('Favor preencha todos os campos.')</script>";
}else{
if (isset($hostp))
{
$resulta = pg_fetch_array($consulta);
} else {
$resulta = $consulta->fetch_array();
}
while ($resulta) {
$idservico = $resulta['id_serv'];
$media = @round($totalAtendimentos / $quantidadePessoas);
if($idservico != $idservicoAnterior)
{
if($idservicoAnterior != -1)
{
echo "<tr>
<td style='width: 200px; background-color: #D3D3D3;'></td>
<td style='background-color: #D3D3D3;'>Média</td>
<td style='background-color: #D3D3D3;'>$media</td>
<td style='background-color: #D3D3D3;'></td>
</tr>
</table> <br/>";
}
$totalAtendimentos = 0;
$quantidadePessoas = 0;
echo "<table border=1>
<tr style='background-color: #D3D3D3;'>
<td>Setor</td>
<td>{$resulta['nm_serv']}</td>
<td>Total Atendimentos</td>
<td>Percentual x Média</td>
</tr>";
}
$totalAtendimentos += $resulta['total'];
$quantidadePessoas += 1;
$idservicoAnterior = $idservico;
echo "<tr>
<td>{$resulta['desc_serv']}</td>
<td>{$resulta['nm_usu']}</td>
<td>{$resulta['total']}</td>
<td>O VALOR DO CÁLCULO VEM AQUI</td>
</tr>";
I know the style of code isn’t right, but I’m still learning. In case you need any more information I’m available to help to be helped.
Yes, I’ve tried to do something here, but nothing that would work. =(
– phpricardo
To achieve something like this, $resultsPorc = round(($results['total'] * 100) / 354); but I need that instead of 354 (which was a test) the dynamic result of the average of all appointments.
– phpricardo
Do as in the shopping carts, create a variable $media = 0 out of the loop and within the loop sum it $media += $soma_total and then print the $media out of the loop again.
– Edilson
I think I understand your idea, but not how to apply it to my case.
– phpricardo
Give me a few minutes I’m on tel. when I get back to PC I have to show you the practical way.
– Edilson