Just started learning php and this is my first project: sort list items and save that new order to database. But I'm really stuck on how to save the order with the new order numbers.
I have an array like this: order numbers
and I want to loop through this and update the ordernumber column in my table.
so far I have this set up:
foreach ($a as $key => $neworder) {
$sql = "UPDATE todoitem SET ordernumber = '$key' WHERE Id = '$neworder'";
}
But when I sort the list items, I get this: todoitem table
Only the last row gets updated and the order number is 3? I don't understand where the 3 come from.
I've been scratching my head at this for a few days and I'm so stuck...