Hello Readers if you want to update mulitple record by multiple id, then you have to use in clause in MySql
Lets see the example as below:-
$ids = array(474,25, 99,101);
Here I have an array $ids with multiple id's. Now this array will be inserted into mysql query.
$params = implode(",", array_fill(0, count($ids), "?"));
$sql = "UPDATE MyTable SET LastUpdated = GETDATE() WHERE id IN ($params)";
$stmt = $mysqli->prepare($sql);
call_user_func_array(array($stmt, 'bindparams'), $ids);
$stmt->execute();
$stmt->close();
echo "Updated record IDs: " . implode("," $ids) ."\n";
0 Comment(s)