I have a problem with a part of the code in which, through a foreach I go through an array and those that meet certain conditions are updated by an UPDATE value. The problem is that I try to pass the values with a hidden input and only update the last value. How can I modify the code so I can do it with arrays?
try {
$add = "UPDATE calculo SET puntaje_fecha=:puntaje_fecha WHERE id_calculo=:id_calculo";
$d = $conn->prepare($add);
$d->bindParam(':puntaje_fecha', $_POST['puntaje_fecha']);
$d->bindParam(':id_calculo', $_POST['id_calculo']);
$d->execute();
} catch (PDOException $e) {
die("Error: " . $e->getMessage() . "<br>on line: " . $e->getLine() . "<br>on file: " . $e->getFile());
}
<form action="actualizar.php" method="post">
<?php foreach ($ca as $c){?>
<?php foreach ($pr as $p) {}?>
<?php if (($p['id_fecha'])==($c['nFecha'])){
//actions to be taken if the conditions are met
}?>
<input type="hidden" name="puntaje_fecha" value="<?php echo $s; ?>">
<input type="hidden" name="id_calculo" value="<?php echo $c['id_calculo']; ?>">
<?php }} ?>
<input type="submit" value="Actualiza puntos">
</form>
What I need is that in my "calculo" table all the values of "puntaje_fecha" are updated as long as they meet that condition. Many people have recommended me to change the name of the input by arrays, but I do not know how to do it. Thank you very much to anyone who can help me.