is looping from 0-3 (since there are 4 keys in your array by those numbers).
$sql = "UPDATE todoitem SET ordernumber = '$key' WHERE Id = '$neworder'";
Is setting the $sql variable to a string, built by the $key and $neworder values.
Now, the code never actually does anything with that query inside that loop. It just over-writes it each time. So the last iteration of the loop will be the value of $sql after the loop. (Presumably that's where you're actually using it in some way.)
If my assumption is correct and you are executing the query after the loop, then the code is semantically doing the following:
Set the query to use 0.
Set the query to use 1.
Set the query to use 2.
Set the query to use 3.
Execute the query.
It's only executed once. Maybe you meant to execute the query inside of the loop?
Asked in February 2016Viewed 2,406 timesVoted 5Answered 2 times