Let's say I have 5 lines with fields id, catnameand order:
+----+----------+-----+
| id | catname |order|
+----+----------+-----+
| 1 | cat1 | 2 |
| 2 | cat2 | 1 |
| 3 | cat3 | 3 |
| 4 | cat4 | 5 |
| 5 | cat5 | 4 |
+----+----------+-----+
and I want to update the order of these 5 categories from the array, for example:
array(1 => 3, 2 => 4, 3 => 5, 4 => 1, 5 => 2)
What is the best practice? To select each row and update the ordinal fields with the corresponding order in the array? Or create a new table containing an array of orders of all these categories, and use it to organize and link the two tables with the join operator, for example, using userid?
source
share