So I have two arrays that I need to update and set with in MySQL. item_id [1,2,3] and item_order[2,1,3]
Here is the items table before the array insert:
item_id item_order
1 1 //should become 2
2 2 // should become 1
3 3 // should become 3
The arrays should be in pairs for the insert, 1-2, 2-1, 3-3.
How can I do this with a prepared statement efficiently and how can I test if the array items are indeed numbers?
Assuming you have input like this:
You can try something like this. (I’m also assuming you have PDO configured to throw exceptions when problems arise).
But it might be better to redesign your input – only pass the
item_idsin the desired order and compute theiritem_ordervalues automatically.