I want to update multiple rows with multiple wheres. When i update only 1 input field it works perfecly, but when i update diffrent weeks and field the query fails. I dont know how to put this code togetter. I already search on google and stackoverflow but could not find something that fits my question.
here is my code
if(isset($_POST["opslaan"]))
{
unset($_POST["opslaan"]);
foreach($_POST as $input => $inner_arr)
{
foreach($inner_arr as $week => $value)
{
$update_query[] = $input." = '".$value."' WHERE week = ".$week;
}
}
$test = implode(", ", $update_query);
echo $test;
if(mysqli_query($conn, "UPDATE buitenklimaat SET ".$test))
{
header("location: dashboard.php?user=1&page=gewasregistratie");
echo "done";
}
else
{
echo "Failed !";
}
}
echo output:
gem_buitentemperatuur_etmaal = '1' WHERE week = 1,
gem_buitentemperatuur_etmaal = '2' WHERE week = 2,
gem_buitentemperatuur_etmaal = '3' WHERE week = 3