Inputs within the While

0

I would like to know how I can do to have inputs sending different values inside a while loop:

<form method="POST" name="form" action="<?php echo $_SERVER['PHP_SELF'];?>">
<?php while ($linhasMotoristas = mysqli_fetch_array($consultaMotoristas)) {
$motoristasStatus = $linhasMotoristas['status'];
$motoristasId = $linhasMotoristas['idmotoristas'];
$motoristasNome = $linhasMotoristas['nome'];
$motoristasCpf = $linhasMotoristas['cpf'];
$motoristasGanhos = $linhasMotoristas['ganhos']
?>
<tr>
<td class="s">
<?php 
if($motoristasStatus == 1){
echo "<div style='color: green;'>●</div>";
}else{echo "<div style='color: red;'>●</div>";
}
?>
</td>
<td class="m"><?php echo $motoristasId;?></td>
<td class="n"><?php echo $motoristasNome;?></td>
<td class="c"><input type="hidden" name="<?php $td_1 = $motoristasId;?>"><?php echo $motoristasCpf;?>
</td>
<td class="g"><?php echo round($motoristasGanhos, 2);?></td>
<td>                                        
<input type="text" name="valorBruto">
<input type="submit" name="submit">
<?php
if (isset($_POST['submit'])?$_POST['submit'] : 0) {
$valorBruto = $_POST['valorBruto'];
$porcentagemBase = 5/100;
$encargosBase = 25/100;
$vezesPorcentagem = $valorBruto*$porcentagemBase;
$menosEncargosBase = $vezesPorcentagem-$encargosBase;
$resultadoLiquido = $menosEncargosBase*$porcentagemBase;
$resultadoGeral = $resultadoLiquido;
}
?>
<?php echo round($resultadoGeral,2); ?>
<?php echo $td_1;?>
</td>
</tr>
<?php } ?>
</form>

As you can see in the image, it sums all fields with the same value, but I wanted it to add a value for each field.

    
asked by anonymous 10.12.2018 / 16:17

1 answer

0

Failed to send field valorBruto as array by adding bracket with driver id:

<input type="text" name="valorBruto[<?php echo $motoristasId;?>]">

And at the moment of assigning values in the loop to the variable $valorBruto , you get its value from the query to the bank using the same id of the driver:

$valorBruto = $_POST['valorBruto'][$motoristasId];

As you are doing, the variable $valorBruto is having a fixed value sent by the form, not the value of its array field with the id.

    
10.12.2018 / 18:47