I'm trying to update the positions of items from a list upon updating a single item's position, e.g:
- item1
- item2
- item3
- item4
- item5
Moving item5 to position 2 would update the list to:
- item1
- item5 << new position
- item2 << [moved down one]
- item3 << [moved down one]
- item4 << [moved down one]
.
UPDATE subjects SET
position = (CASE WHEN position < {$position} THEN position + 1
WHEN position > {$position} THEN position - 1 else position END CASE)
WHERE position <= position AND position >= {$position};
This SQL query does not work. However what I'd also like to do is IF position < {$position} then have the WHERE clause as what it is now, but if position > {$position} I'd like to have the <= and >= swap around (this will subsequently allow for updating when moving positions up OR down the list
END, notEND CASE. Remove that lastCASE- Michael Berkowski