At first, I have got the following:
$sql="SELECT sum(importe_subproyecto) as importe_total FROM presupuestos_pmt WHERE oferta_numero = '$oferta_numero'";
$result = mysqli_query($con,$sql);
while ($row = mysqli_fetch_assoc($result))
{
$importe_total = $row['importe_total'];
}
which stores the sum of "importe_total" in a variable of the same name. Then, there is the following:
$sql="UPDATE presupuestos_pmt SET `importe_total` = '$importe_total' WHERE `oferta_numero` = '$oferta_numero'";
mysqli_query($con,$sql);
which introduces the variable calculated previously in the rows of interest.
And finally,
$rowcount = mysqli_affected_rows($con);
Which counts the affected rows.
The script works correctly when all the fields "importe_subproyecto" are greater than 0, but row_count returns 1 when one of the fields "importe_subproyecto" is 0 even if there are 3,4,5... updated rows.
Do somebody know why?
EXAMPLE:
When summing the project 0002, this would give a row count of 1 because one of the fields importe_subproyecto
is 0