is there a way to use multiples mysql UPDATE with only 1 query?
I need something like this but the code below seems to be not right.
$sql = "UPDATE car_models SET date='$date' WHERE ";
foreach ( $modelos as $mod ){
$sql .= "(name='$mod->Label' AND car='$mod->model') AND ";
}
$sql = substr($sql, 0, -4);
$res = mysqli_query($con, $sql);
At the end I was expecting to have the $sql like this:
$sql = "UPDATE car_models SET date='$date' WHERE (name='$mod->Label' AND car='$mod->model') AND (name='$mod->Label' AND car='$mod->model') AND (name='$mod->Label' AND car='$mod->model')";
Should it work? Or there is a different way to do this?
Thanks
Try to put OR
instead of AND
at the end of the string:
$sql .= "(name='$mod->Label' AND car='$mod->model') OR ";
And pay close attention to ""
.
You can do UPDATE car_models SET date='$date' WHERE name IN $array_of_car_name AND car IN $array_of_car_model